Skip to main content
December 12, 2012
Question

AIR app crashes on iOS after returning from CameraUI photo capture

  • December 12, 2012
  • 1 reply
  • 3134 views

So, I've been running into this problem in one way or another for as long as we've had CameraUI access. It seems that each time another version of AIR comes out Adobe claims the problem has been fixed, and each time I find that the problem hasn't. So, here we go:

I'm running an AIR 3.4 application on a range of devices: iPod Touch (previous generation), iPhone 5, iPhone 4S, iPhone 4, and iPad 2. All the test devices are loaded with the latest version of iOS. On every one of them, if the user takes a few photos in a row the application crashes by quietly returning to the desktop. On Android devices, the same happens when I take even a single photo. In fact, when running the application in the debugger I can see that the process terminates not when the app returns from CameraUI, but as soon as the native Camera is invoked.

This problem has been going on forever. What is the fix?

This topic has been closed for replies.

1 reply

sinious
Legend
December 12, 2012

Can you post the code you're using so we can verify and reproduce the issue. I have all generations of iPhones, iPads (except Mini) and several android tablets and phones.

December 12, 2012

sinious, I'm running code in a rather large application and I'm not sure (professionally) what I'm allowed to share. I can *probably* document with some pseudocode and small snippets though:

1. Declare an instance of CameraUI

var cam:CameraUI = new CameraUI();

cam.addEventListener(Event.CANCEL, _captureMobileCancel, false, 0, true);

cam.addEventListener(MediaEvent.COMPLETE, _captureMobileComplete, false, 0, true);

cam.launch(MediaType.IMAGE);

2. In the complete handler, I acquire the image using a MediaPromise

var promise:MediaPromise = e.data as MediaPromise;

var bytes:ByteArray = new ByteArray();

var input:IDataInput = promise.open();

input.readBytes(bytes, bytes.length, input.bytesAvailable); 

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _imageLoaded, false, 0, true);

loader.loadBytes(bytes);

3. Once the image has finished loading, I drop it into a Sprite, perform some transformations, and then draw the cropped contents of the Sprite to a new Bitmap. This is purely an aesthetic requirement baesd on the design and purpose of the app I'm developing.

4. I take the new Bitmap I've just generated, convert it to a JPG, and write it manually to the file system. I write it manually because I need direct access to each image for display in multiple locations throughout the application, so this isn't a scenario where I can just ask the user to browse the camera roll to select the image.

Anyway, after taking a few photos (the number varies), the app exits to the desktop.

Is this helpful enough?

EDIT: I should also clarify that I have no issues interacting with images acquired in this manner. I'm able to successfully read and write them to the iPhone's internal storage, upload and view them via a webserver, and interact with and display them in the application.

Colin Holgate
Inspiring
December 12, 2012

I don't use loadBytes(), I do this:

imageLoader = new Loader();

imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );

imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );

imageLoader.loadFilePromise( imagePromise );

and when the asyncImageLoaded happens I can get the image from the imageLoader:

bm = imageLoader.content as Bitmap;

bmd = bm.bitmapData;

Then later, after I have used that image for what it's for, I dispose of the original one:

bm.bitmapData.dispose();

bmd.dispose();

System.gc();

Before I did those things I would get crashes after a couple of pictures were taken.