EXC_BAD_ACCESS starting / stopping Vuforia

April 23, 2015 - 10:47am #1

In a native iPhone app I have a UIViewController set up to show AR based on the ImageTargets sample app, using Vuforia 4.0. The view It works fine in general, but if a user opens and closes the vuforia view rapidly, it causes an EXC_BAD_ACCESS exception in SampleApplicationSession, on this line:


if (!QCAR::CameraDevice::getInstance().start()) {

        [self NSErrorWithCode:-1 error:error];

        return NO;



What is the recommended approach for preventing this type of crash? It seems Vuforia does some background threading when first starting up, so what I need is a way to cancel all of that without causing a crash. 



Here are some details about how I have it set up.



In my UIViewController, in viewDidLoad, I have the following:


[self handleARViewRotation:self.interfaceOrientation];

    eaglView = [[VuforiaEAGLView alloc] initWithFrame:self.view.frame appSession:vapp backgroundShader:self.bgShaderName overlay:self.overlayView];

    eaglView.delegate = self;

    [self.view addSubview:eaglView];

    [vapp initAR:QCAR::GL_20 ARViewBoundsSize:viewFrame.size orientation:UIInterfaceOrientationLandscapeRight]; 


In viewWillAppear:


[self handleARViewRotation:self.interfaceOrientation];


And in viewWillDisappear:

[vapp stopAR:nil];

[eaglView finishOpenGLESCommands];



The ImageTargetsEAGLView.mm and SampleApplicationSession.mm classes are unchanged from the sample code.


Note, I am adding the view controller as a child view controller of another view controller (using the technique listed here: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html), and positioning its view using autolayout. That is why I added the eaglView as a subview.


Thanks in advance for your help!

EXC_BAD_ACCESS starting / stopping Vuforia

April 28, 2015 - 7:49pm #2

EXC_BAD_ACCESS is a general error that could be due to null pointer access. Since you are starting and stopping app rapidly, the camera may still be initializing. Are you doing checks to make sure camera is ready before calling start()?

Log in or register to post comments