[TIMOB-14540] Android: blob.imageAsResize causes java error
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-08-16T23:22:10.000+0000 |
Affected Version/s | Release 3.1.1, Release 3.2.0 |
Fix Version/s | 2013 Sprint 17, 2013 Sprint 17 API, Release 3.2.0 |
Components | Android |
Labels | mobilesdk, module_media, qe-testadded, titanium |
Reporter | Ashish Nigam |
Assignee | Ping Wang |
Created | 2013-07-12T13:16:39.000+0000 |
Updated | 2014-06-19T12:44:08.000+0000 |
Description
*Problem*
When using the imageAsResized function on a blob it causes a java memory error when using a device which has a camera with 6 megapixels or more.
I used the code below on the Galaxy S3, and a lot of times it causes an error, sometimes it doesn't. When i set the camera to 3.2 megapixels for example the issue doesn't occur.
*Steps to reproduce*
1. Tap Open Camera
2. Take photo
3. Save photo
4. Repeat until Runtime Error appears (see attachment)
*Test case*
var win1 = Titanium.UI.createWindow({
title : 'cameratest',
backgroundColor : '#fff'
});
var button = Titanium.UI.createButton({
color : '#999',
title : 'Open camera'
});
win1.add(button);
button.addEventListener("click", function(e) {
Ti.Media.showCamera({
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
success : function(e) {
var width = e.media.width, height = e.media.height, scaleFactor = Math.sqrt((width * height ) / (1600 * 1200 ));
if (scaleFactor > 1) {
width /= scaleFactor;
height /= scaleFactor;
var image = e.media.imageAsResized(width, height);
}
}
});
});
win1.open();
This OutOfMemoryError happens because the image size is too big and the GC does not kick in in time. We cannot control when the GC kicks in, so the developers need to take care of memory wisely. Sent PR https://github.com/appcelerator/titanium_mobile/pull/4509 to handle the error gracefully so the app won't crash any more. For FR, please run the above test case on Galaxy S3 and follow step 1-4 and should not see any crash.
App is running fine with no error, tried several times. Verified fix on: Device: Samsung S3, Android version: 4.1.1 SDK: 3.2.0.v20131018154951 CLI version : 3.2.0 OS : MAC OSX 10.8.4 Alloy : 1.2.2 Appcelerator Studio, build: 3.2.0.201310181700 XCode : 5