Log in or register to post comments

Crash after having presented UIImagePickerController and resuming Camera

February 19, 2014 - 9:06am #1

Vuforia SDK Version: ALL -

Description with steps to reproduce:

I could reproduce the crash on the VUFORIA Sample, coding in the ImageTargetsViewController.mm

  1. When using the ImageTarget Sample, pause the AR:  [vapp pauseAR:&error];
  2. Show the UIIMagePickerController (Source type camera)
  3. On dismiss of the picker release it and resume AR [vapp resumeAR:&error];
  4. It will crash on the init of the camera: QCAR::CameraDevice::getInstance().init(mCamera);

LOG reports this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The activeVideoMinFrameDuration passed is not supported by the receiver's active format.  Use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges.'

*** First throw call stack:

(0x2e1bef4b 0x3854e6af 0x2d0cce0b 0x184a4f 0x1861d1 0x12e519 0x367607 0x11ef49 0x11e169 0x84d03 0x5bd61 0x80169 0x2eb9938b 0x2e18a0df 0x2e189cf7 0x2e188093 0x2e0f2c27 0x2e0f2a0b 0x32dd1283 0x30996049 0x5aa43 0x5a268)

libc++abi.dylib: terminating with uncaught exception of type NSException

 

Picker is shown on tap on the AR, this way:

 

- (void)autofocus:(UITapGestureRecognizer *)sender

{

    NSError *error = nil;

    [vapp pauseAR:&error];

    

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.modalPresentationStyle = UIModalPresentationCurrentContext;

    picker.allowsEditing = YES;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.delegate = self;

    [self presentViewController:picker animated:YES completion:nil];

}

 

On dismiss I resume this way:

 

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

   

    [self dismissViewControllerAnimated: YES completion:^{

    

        //destroy picker

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [picker release];

        

        [self performSelector:@selector(reinit) withObject:nil afterDelay:2];

    }];

}

 

- (void) reinit {

    NSError * error = nil;

    [vapp resumeAR:&error];

}

 

 

Sorry, its five minutes code, so may contain errors;

-

Development OS (Mac OS X, Windows, Linux): MAC OS X -

Mobile OS and Version: iOS 7.0.4 -

Mobile Device Manufacturer and Model name: Apple iPhone4 -

Do the Vuforia Sample Applications show the same behavior?: Yes, slightly modified

Crash after having presented UIImagePickerController and resumin

April 14, 2014 - 6:52am #22

because none of the workarounds posted below work for us?

Why not?

Please check the code and try again.

 

N

Crash after having presented UIImagePickerController and resumin

April 14, 2014 - 6:43am #21

Hi, we are experiencing the same issue. Is the development team working on a fix for this because none of the workarounds posted below work for us?

Crash after having presented UIImagePickerController and resumin

March 27, 2014 - 10:15am #20

Great - many thanks for the update :)

N

Crash after having presented UIImagePickerController and resumin

March 27, 2014 - 9:04am #19

Ok... I now have everything working.  I had to use a combination of both Tom Wilson solution and the first solution and your solution that had this code for the pauseAR:

    [vapp pauseAR];    //  in my code I rename "vapp" to "arSessUtil". Has more meaning... lol

    [self doStopTrackers];

    [self doUnloadTrackersData];

    [self doDeinitTrackers];

 

    QCAR::deinit();

 

This cleanup is required in order to cleanly resume the AR session.

 

Code I added to CloudRecoViewController for resuming AR -

I added Tom's methods, and then added as the last statement in loadView:

  [self saveCaptureFormat];

 

And in ViewWillAppear, before the resumeAR:

  [self restoreCaptureFormat];

Crash after having presented UIImagePickerController and resumin

March 27, 2014 - 8:19am #18

Working on them right now.

The crash stopped in the resumeAR.  But the EaglView scanning is not fully engaging... I think I'm just missing something obvious.

I'm reviewing my code..  I'll keep you up to date...

Crash after having presented UIImagePickerController and resumin

March 27, 2014 - 3:59am #17

Have you tried the two workarounds posted below?

 

N

Crash after having presented UIImagePickerController and resumin

March 26, 2014 - 2:59pm #16

I am having the exact same issue in Cloud Recognition.  I am upgrading to SDK 2-8-7 and nearly completed except for this error.  I am getting the exact same error at the exact same location as the other when doing a resumeAR.  I have this App in the App Store using a 2.6.8 SDK which is working great, but I want to stay up to date on the SDK, thus the upgrade.

The flow of what I am doing:

1. Start up CloudReco, which initializes and kicks off CloudEaglView

2. Image is recognized, I have the key returned to me.

3. I pauseAR and kickoff a Storyboard based viewcontroller, which allows me to do various other things such as run videos, webviews, etc.

4. When done, I pop back to the CloudReco and perform a resumeAR.

5. This is where it crashes, just like what the others are getting.

 

Here is the exact message and I have attached a screen shot showing the statement that is failing:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The activeVideoMinFrameDuration passed is not supported by the receiver's active format.  Use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges.

AttachmentSize
Image icon SDK_2-8-7_Error1.png84.96 KB

Crash after having presented UIImagePickerController and resumin

March 26, 2014 - 4:20am #15

Thanks very much for this Tom.

I have passed this on to the development team - much appreciated.

 

cheers

N

Crash after having presented UIImagePickerController and resumin

March 25, 2014 - 1:04am #14

Hi tomwilson,

this seems promising, especially a good hint for Vuforia guys to fix this.

Thank you very much for your contribution.

Crash after having presented UIImagePickerController and resumin

March 24, 2014 - 6:08pm #13

I'm not doing quite the same thing (I'm using a bunch of AV* stuff to present a custom photo user interface), but the end result is still the same with the same crash reported.

However I have figured out workaround. Before you do your camera stuff, save the current capture format and frame rate settings, and then restore them again when you are done.

@interface PhotoBoothCameraUI(VuforiaFix)

@property (strong, nonatomic) AVCaptureDeviceFormat *captureFormat;

 

@property (assign, nonatomic) CMTime captureMinFrameRateDuration;

@property (assign, nonatomic) CMTime captureMaxFrameRateDuration;

@end

 

- (void) saveCaptureFormat

{

    // Vuforia 2.8 workaround on iOS7 - save the current format and frame rate durations

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {

        AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

        self.captureFormat = videoDevice.activeFormat;

        self.captureMinFrameRateDuration = videoDevice.activeVideoMinFrameDuration;

        self.captureMaxFrameRateDuration = videoDevice.activeVideoMaxFrameDuration;

    }

}

 
And then after your camera stuff, restore them:
 

- (void) restoreCaptureFormat

{

    // Vuforia 2.8 workaround on iOS7 - restore the format and frame rate durations

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {

        AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

        [videoDevice lockForConfiguration:nil];

        videoDevice.activeFormat = self.captureFormat;

        videoDevice.activeVideoMaxFrameDuration = self.captureMaxFrameRateDuration;

        videoDevice.activeVideoMinFrameDuration = self.captureMinFrameRateDuration;

        [videoDevice unlockForConfiguration];

}

You should now be able to resume vuforia from where you were, without it crashing.

I havent finished testing this across that many devices yet so your mileage may vary.. but its a start :-)

Crash after having presented UIImagePickerController and resumin

February 26, 2014 - 4:22am #12

Great to hear this is working for you :)

I have notified the development team and hopefully they will fix this in a future release.

 

cheers,

N

Crash after having presented UIImagePickerController and resumin

February 25, 2014 - 8:36am #11

Hi,

the good news is that its not crashing anymore. Do you think this might get fixed somehow in the future or the hard deinitialization workaround will be the only way to get this working? Did you understand what is happening at low level at the camera state?

Thank you for your precious help.

Jsoef

Crash after having presented UIImagePickerController and resumin

February 25, 2014 - 7:43am #10

Hi Josef,

After talking to the development team and doing a few experiments I have come up with a few modifications that should enable this code to work across all devices.

This does mean that the Vuforia instance is effectively shut-down before the ImagePickerController appears, and it means that restarting it all again will take a little bit of time.

Try the code below and let me know how you get on.

 

HTH

N

 

- (void)autofocus:(UITapGestureRecognizer *)sender

{

    NSError *error = nil;

    [vapp pauseAR:&error];

 

    [self doStopTrackers];

    [self doUnloadTrackersData];

    [self doDeinitTrackers];

 

    QCAR::deinit();

        

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.modalPresentationStyle = UIModalPresentationCurrentContext;

    picker.allowsEditing = YES;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.delegate = self;

    [self presentViewController:picker animated:YES completion:nil];

}

 

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

    

    [picker dismissViewControllerAnimated: YES completion:^{

        

        [self performSelector:@selector(reinit) withObject:nil afterDelay:2];

 

    }];

}

 

- (void) reinit {

 

    [vapp performSelectorInBackground:@selector(initQCARInBackground) withObject:nil];    

}

Crash after having presented UIImagePickerController and resumin

February 24, 2014 - 3:43am #9

I will try to look at this today, and yes this seems specific to non iPhone5S devices on iOS7 - iOS6 seems ok.

I will revert back when I have more info.

N

Crash after having presented UIImagePickerController and resumin

February 24, 2014 - 3:41am #8

Today I could test with other devices; seems to work only on iPhone5s, while on Iphone5, Iphone4 & Iphone4s it persist crashing (even with latests iOS 7.0.6)

Can you test with another device than iphone 5s?

Best Regards

Crash after having presented UIImagePickerController and resumin

February 21, 2014 - 12:29am #7

Hi,

using your code as is does not work, because you probably erroneously inverted the deinit call with the stop call; you need to call stop before deinit.

BTW, returning to my original code and using the SampleApplicationSession resumeAR and pauseAR calls it crashes always in the

QCAR::CameraDevice::getInstance().init(mCamera)

Attaching the modified ImageTargetsViewController.mm  

Today I can test only on iPhone4

Best Regards

AttachmentSize
Package icon ImageTargetsViewController.mm_.zip4.89 KB

Crash after having presented UIImagePickerController and resumin

February 20, 2014 - 9:38am #6

With those lines of code it crashes. You may notice that now it looks as my first code which was calling:

NSError *error = nil;
[vapp pauseAR:&error];

Unfortunately now I'm out of office and will give you more feedback tomorrow morning.

Crash after having presented UIImagePickerController and resumin

February 20, 2014 - 9:22am #5

It seems I forgot to add a couple of lines for QCAR::onPause(); and QCAR::onResume();

 

Try this (with init & deinit) - seems to work on iOS7

 

HTH

N

 

- (void)autofocus:(UITapGestureRecognizer *)sender

{    

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

        NSLog(@"Error deinit camera");

    }

    

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

 

        NSLog(@"Error stopping camera");

    }

 

    QCAR::onPause();

    

    

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.modalPresentationStyle = UIModalPresentationCurrentContext;

    picker.allowsEditing = YES;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.delegate = self;

    [self presentViewController:picker animated:YES completion:nil];

}

 

 

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

    

    [picker dismissViewControllerAnimated: YES completion:^{

 

        QCAR::CameraDevice::CAMERA camera = QCAR::CameraDevice::CAMERA_DEFAULT;

        if (! QCAR::CameraDevice::getInstance().init(camera)) {

            NSLog(@"Error initing camera");

        }

        

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

            

            NSLog(@"Error starting camera");

        }

        

        QCAR::onResume();

    }];

}

Crash after having presented UIImagePickerController and resumin

February 20, 2014 - 9:07am #4

 you write that it is simply necessary to stop the camera. Is that correct?

 

Yes this should be possible.  In the previous samples pause/resume was the best way to suspend activity rather than going the whole route with init/deinit

 

I have just tried on iPhone 5S iOS7 and see a similar picture to the one you attached, yet it does not crash.  However on iOS6 it is fine.

 

I do not see this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The activeVideoMinFrameDuration passed is not supported by the receiver's active format.  Use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges.'

 

Is this something to do with your EAGLView?  as you must be doing something different.

 

N

Crash after having presented UIImagePickerController and resumin

February 20, 2014 - 8:54am #3

Hi,

Attached the screenshot of what I get using your modifications, after dismissing the UIImagePickerController.

Actually my feeling is like the UIIMagePickerController is altering the camera settings which is shared with Vuforia. The screenshots shows something like a format problem.

Before looking at your code I was sure that before hiding the AR stuff it was necessary to stop and deinit the camera; you write that it is simply necessary to stop the camera. Is that correct?

When calling resumeAR and pauseAR (like in my original code) the application crashes and again my suspect goes to the UIIMagePickerController altering the camera settings, which are not correct with the ones Vuforia tries to use. I report again the error here:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The activeVideoMinFrameDuration passed is not supported by the receiver's active format.  Use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges.'

Its a iOS7 only error as it does not arise in iOS6; Also it does not appear on iPad, but could reproduce it on the iPhone4, iPhone4S, iPhone5

Attaching the ImageTargetsViewController.mm I'm using.

PS: Sorry for my original code not being clear, but I'm working on this issue since many days, and as I could reproduce the bug in your samples I though to report it.

Thank you and let me know how I can give more feedback. 

 

Crash after having presented UIImagePickerController and resumin

February 20, 2014 - 4:47am #2

Sorry, its five minutes code, so may contain errors;

In future you might like to spend more than 5 minutes to fully debug your code before posting on forums...

Here's a cleaned up version:

- (void)autofocus:(UITapGestureRecognizer *)sender

{

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

        NSLog(@"Error stopping camera");

    }    

    

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.modalPresentationStyle = UIModalPresentationCurrentContext;

    picker.allowsEditing = YES;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.delegate = self;

    [self presentViewController:picker animated:YES completion:nil];

}

 

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

    

    [picker dismissViewControllerAnimated: YES completion:^{

        

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

            

            NSLog(@"Error starting camera");

        }

        

    }];

}

When I tried your code as is I did not get any crash, nor with the cleaned up version above.

The problem I encountered was that the camera would not restart due to some lifecycle problems.  I managed to work around this by amending viewWillDisappear to remove the stopping of the AR:

- (void)viewWillDisappear:(BOOL)animated {

//    [vapp stopAR:nil];

    // Be a good OpenGL ES citizen: now that QCAR is paused and the render

    // thread is not executing, inform the root view controller that the

    // EAGLView should finish any OpenGL ES commands

    [eaglView finishOpenGLESCommands];

 

}

..because otherwise the camera fails to restart properly.

Note that in this case you will need to manage your lifecycle accordingly.

 

HTH

N

 

 

Log in or register to post comments