navigator.camera.getPicture() crashing on iOS, ARC errors and memory warnings.

2,589 views
Skip to first unread message

KJ

unread,
Feb 21, 2012, 7:43:56 PM2/21/12
to phonegap
Hello there,
This is my first post to the group.

I'm having an issue with Phonegap 1.4.1 and using Sencha Touch 2.

When I trigger the getPicture method through a simple button tap my
app throws a memory warning before crashing out completely. It only
seems to crash when I take the image or click cancel on the default
camera screen on iOS5.

I'm calling it using the following code placed inside my button
listener:

navigator.camera.getPicture(this.onCaptureImageSuccess, this.onFail,
{ quality: 50,
destinationType: Camera.DestinationType.FILE_URI });

My app runs fine until I try and take a photo with the camera and then
I get the following dump to my xcode IDE log:

2012-02-22 00:42:02.135 myapp[26137:707] [INFO] on capture image
pressed
[Switching to process 7171 thread 0x1c03]
2012-02-22 00:42:05.684 myapp[26137:707] Received memory warning.
2012-02-22 00:42:13.974 myapp[26137:707] -[__NSCFString
pickerController]: unrecognized selector sent to instance 0x12b8c0
2012-02-22 00:42:13.979 myapp[26137:707] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-
[__NSCFString pickerController]: unrecognized selector sent to
instance 0x12b8c0'
*** First throw call stack:
(0x3806b8bf 0x31b511e5 0x3806eacb 0x3806d945 0x37fc8680 0x14253
0x3568af5f 0x363bba79 0x363cce2f 0x363fa167 0x363fa027 0x363a7bf1
0x363d19af 0x37fc5435 0x3543e9eb 0x3543e9a7 0x3543e985 0x3543e6f5
0x3543f02d 0x3543d50f 0x3543cf01 0x354234ed 0x35422d2d 0x37b40df3
0x3803f553 0x3803f4f5 0x3803e343 0x37fc14dd 0x37fc13a5 0x37b3ffcd
0x35451743 0x2f6f 0x2ef4)
terminate called throwing an exception(gdb)

Does anyone have an ideas?

In my build settings my compiler is set to LLVM GCC 4.2

Thanks.

Devgeeks

unread,
Feb 22, 2012, 3:48:29 AM2/22/12
to phon...@googlegroups.com
Personally, I would avoid ARC with PhoneGap projects.

KJ

unread,
Feb 22, 2012, 4:28:20 AM2/22/12
to phonegap
I thought I had turned it off. I'd read elsewhere that this was
recommended; to have it turned off and to set the compiler to LLVM GCC
4.2 but I still get those errors.

Devgeeks

unread,
Feb 22, 2012, 5:40:17 AM2/22/12
to phon...@googlegroups.com
To get rid of ARC if you accidentally have it on, see the steps listed in the BarCode Scanner plugin (I know you aren't using that plugin, but the concepts are the same).


See the section called: "Compile Errors for Automagic Reference Counting (ARC)"

KJ

unread,
Feb 22, 2012, 6:50:56 AM2/22/12
to phonegap
Thank you for your help and advice Devgeeks. I read that article last
night and tried the first two options. I might have to do it file per
file (3rd option) or just create a new project to be sure.


On Feb 22, 10:40 am, Devgeeks <to...@devgeeks.org> wrote:
> To get rid of ARC if you accidentally have it on, see the steps listed in
> the BarCode Scanner plugin (I know you aren't using that plugin, but the
> concepts are the same).
>
> https://github.com/phonegap/phonegap-plugins/blob/master/iPhone/Barco...

KJ

unread,
Feb 22, 2012, 2:35:36 PM2/22/12
to phonegap
I've now got rid of the ARC related errors but the app still throws an
exception when I either take a photo or cancel taking a photo.

I get the following output, which is pretty much the same as in my
initial post...

2012-02-22 19:31:47.594 MyApp[26399:707] Received memory warning.
2012-02-22 19:31:54.130 MyApp[26399:707] -[__NSArrayM
pickerController]: unrecognized selector sent to instance 0x160670
2012-02-22 19:31:54.138 MyApp[26399:707] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM
pickerController]: unrecognized selector sent to instance 0x160670'
*** First throw call stack:
(0x3806b8bf 0x31b511e5 0x3806eacb 0x3806d945 0x37fc8680 0x1426b
0x3568af5f 0x363bba79 0x363cce2f 0x363fa167 0x363fa027 0x363a7bf1
0x363d19af 0x37fc5435 0x3543e9eb 0x3543e9a7 0x3543e985 0x3543e6f5
0x3543f02d 0x3543d50f 0x3543cf01 0x354234ed 0x35422d2d 0x37b40df3
0x3803f553 0x3803f4f5 0x3803e343 0x37fc14dd 0x37fc13a5 0x37b3ffcd
0x35451743 0x2e5b 0x2de0)
terminate called throwing an exceptionCurrent language: auto;
currently objective-c


I'm not sure what else to try. I have a really small project and the
only really functionality in it is Facebook login and the camera. I've
made sure the Facebook plugin is also building without ARC.

KJ

unread,
Feb 22, 2012, 2:49:42 PM2/22/12
to phonegap
Also, in Xcode I see this in the debugger

programe received signal EXC_BAD_ACCESS

which points to this line in main.m

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
Message has been deleted

KJ

unread,
Feb 22, 2012, 5:11:26 PM2/22/12
to phonegap
I've just rebuilt the project from scratch but this time making sure 
the checkbox for ARC was unchecked, and still getting this error :(

Phonegap v 1.4.1
Sencha Touch 2 beta 3
Xcode  4.2
Compiler LLVM GCC 4.2
Base SDK Latest IOS 5

I've also just tried using the geolocation API for phonegap and this
worked perfectly. It seems to be an issue with the camera api. Could
this be a bug?

Not sure what else to try.

Devgeeks

unread,
Feb 22, 2012, 7:20:31 PM2/22/12
to phon...@googlegroups.com
Are you using FILE_URI or DATA_URL for Camera.DestinationType?

If you are using DATA_URL on a phone like an iPhone4 with a pretty good camera without scaling the image in the options (i.e.: targetWidth or targetHeight) that could very well be the cause of your problem. A 1600x1200 or whatever image can get pretty big uncompressed and in Base64. I got the same problem when I was using DATA_URL with no resizing.

I have been returning FILE_URI in my app and using a targetWidth of something around 720 (since the final image is intended for social networks) and I can take photos all day without getting a memory warning. 

KJ

unread,
Feb 22, 2012, 7:52:56 PM2/22/12
to phonegap
Hi,
I've been using FILE_URI as that's what I see recommended everywhere
that I've read.

My camera options are set as follows:

navigator.camera.getPicture(this.onCaptureImageSuccess, this.onFail,
{
quality : 10,
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100 }
);

Looking at that I would definitely not be expecting to see memory
issues. I have noticed that very rarely I can take a shot or two
before it crashes.

Crazy stuff.

KJ

unread,
Feb 22, 2012, 8:23:02 PM2/22/12
to phonegap
This actually is pretty crazy. I turned my iPhone off (the first time
since I started developing for it in fact) and my app is working. I
just fired off several images and geolocation calls without error. In
fact, it's running super smooth now, touch wood. Could this be the
result of some sort of caching issue with the app when it's run on the
device from xcode?

Devgeeks

unread,
Feb 23, 2012, 1:15:39 AM2/23/12
to phon...@googlegroups.com
Maybe... it could also be a memory leak somewhere... 

Have you ever done any profiling with Instruments?

KJ

unread,
Feb 23, 2012, 5:03:20 AM2/23/12
to phonegap
Hi,
I've not, no. But I'd be interested in it. Any sort of debugging tool
would be great. I'm not a fan of xcode so have been using Textmate to
do my coding. I'll switch to Eclipse soon as that's what I used for
all my AS3 development and debugging over the years.

I'll take a look at Instruments.

Once again, thanks for your time in helping me with my issue. I really
appreciate it.

KJ

unread,
Feb 23, 2012, 5:47:41 AM2/23/12
to phonegap
Just spotted that Instruments is part of XCode. Support I better put
our differences aside and take a look!

Aater Suleman

unread,
Feb 23, 2012, 7:33:46 AM2/23/12
to phonegap
KJ,

The exact same has happened to me once in the past. It wasn't a memory
leak in my case, it was because the Xcode debugger had gotten in a
weird state where the app was running the background as a zombie which
was causing unexpected behavior. Restarting the phone fixed that
problem.

Aater

KJ

unread,
Feb 24, 2012, 10:43:07 AM2/24/12
to phonegap
I had another crash last night, again using the camera, although this
time it wasn't connected to xcode so will need to look at the device
logs. But that was the first time in 48 hours pretty much so it might
not be related.

Will definitely need to give Instruments a try tonight to see if I can
spot the problem.

Richard Kimber

unread,
Mar 24, 2012, 5:07:30 AM3/24/12
to phonegap
I am having exactly the same problems as you describe. The code was
previously working, now crashes constantly. It seems to be since iOS
5.1 for me. Which iOS version are you using?

Shazron

unread,
Mar 24, 2012, 3:23:52 PM3/24/12
to phon...@googlegroups.com
@KJ Crash issues are top priority and should be filed here
http://issues.apache.org/jira/browse/CB - this way you can get
notified of updates. Posting a crash issue here may or may not get the
attention it deserves, since your post might get lost among all the
other posts.

If you can file that issue, that will be great. That way we can
schedule the fix in an upcoming release.

Shaz

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Jonathan Hobson

unread,
Mar 27, 2012, 4:31:01 AM3/27/12
to phon...@googlegroups.com
We've been struggling with this issue for weeks (sometimes it would crash even when trying to take a 10x10px image) and I think I've finally found a solution:

If your app responds to didReceiveMemoryWarning you're telling iOS that you're OK to have all your memory taken away from you and used for other things.

Go into your main view controller and comment out the call to [super didReceiveMemoryWarning];

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    // [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

Which tells iOS to keep its hands off your memory. I think PhoneGap needs to do some bug fixing to properly support memory warnings, which would be good iOS practice, but as our app is only using 2.5mb RAM I don't think it's a huge deal to tell iOS to go away.

Jon
Message has been deleted

Richard Kimber

unread,
Mar 27, 2012, 5:36:00 AM3/27/12
to phon...@googlegroups.com
If this works, you may well be my hero.

On Tuesday, 27 March 2012 09:39:51 UTC+1, Jonathan Hobson wrote:
Comment out the call to [super didReceiveMemoryWarning] from your main view controller:


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    // [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

If you respond to this message you're telling iOS that it can take your memory away from you and you'll re-initialize your views when asked. PhoneGap apparently doesn't support this properly, and instead keeps hold of old memory and then explodes, so until they fix this just remove this line.


onsdag 22. februar 2012 kl. 01:43:56 UTC+1 skrev KJ følgende:

Richard Kimber

unread,
Mar 27, 2012, 9:17:23 AM3/27/12
to phon...@googlegroups.com
I've created an issue on Jira for this. https://issues.apache.org/jira/browse/CB-391

Yuankai

unread,
Mar 29, 2012, 7:24:25 PM3/29/12
to phon...@googlegroups.com
I ran into the same issue and fixed by using the solution suggested by Jonathan Hobson: comment out [super didReceiveMemoryWarning] in 

didReceiveMemoryWarning. 

Here is the repo steps to hit this bug 100% on simulator:

1. Run your code in simulator, call up camera with navigator.camera.getPicture() to open the album (since camera is not available on simulator)
2. Simulator > Hardware > Simulate memory warning
3. Return from the iOS album (either click 'Cancel' or pick a photo)
4. Observe crash of the app

This is because the [super didReceiveMemoryWarning] see the web view is running in background (while the album/camera is on) so released it.  Later when the album/camera closes and tries to call the JS callback, it cannot find the JS handler and hence crash.  Usually in object-c, it is ok to release background views and reconstruct later, just for PhoneGap the web view could not be removed as it is the root view and it has the JS callback to be used later.


Myke

unread,
Mar 29, 2012, 10:55:23 PM3/29/12
to phon...@googlegroups.com
This worked for me - excellent find!

Shazron

unread,
Apr 2, 2012, 8:23:40 PM4/2/12
to phon...@googlegroups.com

Vincente

unread,
May 3, 2012, 2:45:36 AM5/3/12
to phonegap
It does not work for me. Which version phonegap are you using?

Damongo Dev

unread,
May 8, 2012, 8:43:50 PM5/8/12
to phon...@googlegroups.com
Unfortunately, I am still running into this issue with the latest version of Cordova (Phonegap) ver 1.7.0 with XCode version 4.3.2 and IOS version 5.1. on a second generation iPad. Any idea when a fix might be implemented?

> phonegap+unsubscribe@googlegroups.com

Richard Kimber

unread,
May 9, 2012, 2:19:13 AM5/9/12
to phon...@googlegroups.com
If you're still experiencing problems, I recommend posting your comments to the Jira bug. Rich

Kalyani Puvvada

unread,
Jan 9, 2014, 6:00:48 AM1/9/14
to phon...@googlegroups.com
Hi,
I too get the same issue. I tried this solution but it doesn't work for me. Any other solutions?

Thanks,
Kalyani.

Kalyani Puvvada

unread,
Jan 9, 2014, 6:06:42 AM1/9/14
to phon...@googlegroups.com
Hi,
Did you find any solution for this. I too getting same problem..

Thanks,
Kalyani


On Wednesday, February 20, 2013 9:29:33 PM UTC+5:30, Arnout Symoens wrote:
I still have a Received Memory warning problem as of Cordova  2.4
Appears after 1 or more camera shots.
Test case, generates the problem over and over again (IOS 6.1)

Problem is, that after this error my HTML 5 css transitions fail miserable. Probably due to the memory crash..
 

Op woensdag 9 mei 2012 08:19:13 UTC+2 schreef Richard Kimber het volgende:
Reply all
Reply to author
Forward
0 new messages