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.frameappSession:vapp backgroundShader:self.bgShaderNameoverlay:self.overlayView];
eaglView.delegate = self;
[self.view addSubview:eaglView];
[vapp initAR:QCAR::GL_20ARViewBoundsSize: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!
- Development OS (Mac OS X, Windows, Linux): OS X 10.10.3 - Mobile OS and Version: iOS 8.3 - Mobile Device Manufacturer and Model name: Apple iPhone - Do the Vuforia Sample Applications show the same behavior?: The sample app doesn't allow a user to "button mash" in quite the same way, but my app is also 90% the same as the sample ImageTargets app, so in that sense they do
EXC_BAD_ACCESS starting / stopping Vuforia
If you close / reopen the Vuforia view (as a subview), it might be a good idea to also call QCAR::onPause and QCAR::onResume, and to stop the camera and the tracker (see sample code for actual examples of stopping camera and tracker) and then to restart the camera and the tracker when the view is