{ "id": "119849", "key": "AC-2439", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "5", "description": "All attempts at reproducing this issue failed, or not enough information was available to reproduce the issue. Reading the code produces no clues as to why this behavior would occur. If more information appears later, please reopen the issue.", "name": "Cannot Reproduce" }, "resolutiondate": "2013-09-17T23:46:41.000+0000", "created": "2013-09-12T21:59:07.000+0000", "labels": [ "android", "camera", "crash" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:41:29.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "When I try to use imageAsResized or imageAsThumbnail or imagefactory compress the app crashes with an OutOfMemory Error.\r\n\r\nProblem is that this crash happens on devices with 1GB RAM... I think this shouldn't happen for such devices on simple resizing operations.\r\n\r\nI use something like this for generating a thumb and compressing my photos before sending to my servers:\r\n\r\n{code}\r\nTi.Media.showCamera({\r\n allowEditing: false,\r\n mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO,\r\n saveToPhotoGallery: false,\r\n success: function(e) {\r\n \r\n var aspectRatio = e.media.height / e.media.width;\r\n photos[changeImage] = imagefactory.compress(e.media.imageAsResized(640, 640 * aspectRatio), 0.5);\r\n \r\n placeholder[changeImage].setImage(e.media.imageAsThumbnail(194, 0, 0));\r\n },\r\n error: function(e) {\r\n alert(e);\r\n }\r\n});\r\n{code}\r\n\r\n\r\nThis code runs fine on hundreds of devices but crashes on devices like the Samsung Galaxy SII (1GB RAM) and the LG L7 (512MB RAM)\r\n\r\nThis is what I get on logcat:\r\n\r\n{code}\r\n09-12 18:07:39.633: I/Camera(11905): sendBroadcast intent.stop.app-in-app\r\n09-12 18:07:42.613: W/IInputConnectionWrapper(11905): showStatusIcon on inactive InputConnection\r\n09-12 18:07:42.933: D/PiniOn - UALib(11905): Push Service started with intent=Intent { act=com.urbanairship.push.START flg=0x4 cmp=br.com.pinion/com.urbanairship.push.PushService (has extras) }\r\n09-12 18:07:53.443: D/webviewglue(11905): OnTrimMemory with EGL Context 0x4c291980\r\n09-12 18:07:57.278: D/dalvikvm(11905): GC_FOR_ALLOC freed 2632K, 21% free 17099K/21511K, paused 81ms, total 81ms\r\n09-12 18:07:57.278: I/dalvikvm-heap(11905): Forcing collection of SoftReferences for 31961104-byte allocation\r\n09-12 18:07:57.393: D/dalvikvm(11905): GC_BEFORE_OOM freed 11K, 21% free 17088K/21511K, paused 113ms, total 115ms\r\n09-12 18:07:57.393: E/dalvikvm-heap(11905): Out of memory on a 31961104-byte allocation.\r\n09-12 18:07:57.393: I/dalvikvm(11905): \"KrollRuntimeThread\" prio=5 tid=11 RUNNABLE\r\n09-12 18:07:57.393: I/dalvikvm(11905): | group=\"main\" sCount=0 dsCount=0 obj=0x41c37888 self=0x4c4c03f8\r\n09-12 18:07:57.398: I/dalvikvm(11905): | sysTid=11943 nice=0 sched=0/0 cgrp=apps handle=1280051272\r\n09-12 18:07:57.398: I/dalvikvm(11905): | schedstat=( 4318641709 3381257674 10368 ) utm=386 stm=45 core=1\r\n09-12 18:07:57.403: I/dalvikvm(11905): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)\r\n09-12 18:07:57.408: I/dalvikvm(11905): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:652)\r\n09-12 18:07:57.408: I/dalvikvm(11905): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:724)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.titanium.TiBlob.getImage(TiBlob.java:492)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.titanium.TiBlob.imageAsResized(TiBlob.java:525)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)\r\n09-12 18:07:57.413: I/dalvikvm(11905): at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)\r\n09-12 18:07:57.423: I/dalvikvm(11905): at android.os.Handler.handleCallback(Handler.java:615)\r\n09-12 18:07:57.423: I/dalvikvm(11905): at android.os.Handler.dispatchMessage(Handler.java:92)\r\n09-12 18:07:57.433: I/dalvikvm(11905): at android.os.Looper.loop(Looper.java:137)\r\n09-12 18:07:57.433: I/dalvikvm(11905): at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)\r\n09-12 18:07:57.433: D/skia(11905): --- decoder->decode returned false\r\n09-12 18:07:57.438: W/System.err(11905): java.lang.OutOfMemoryError\r\n09-12 18:07:57.438: W/System.err(11905): \tat android.graphics.BitmapFactory.nativeDecodeStream(Native Method)\r\n09-12 18:07:57.438: W/System.err(11905): \tat android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:652)\r\n09-12 18:07:57.448: W/System.err(11905): \tat android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:724)\r\n09-12 18:07:57.448: W/System.err(11905): \tat org.appcelerator.titanium.TiBlob.getImage(TiBlob.java:492)\r\n09-12 18:07:57.448: W/System.err(11905): \tat org.appcelerator.titanium.TiBlob.imageAsResized(TiBlob.java:525)\r\n09-12 18:07:57.453: W/System.err(11905): \tat org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)\r\n09-12 18:07:57.453: W/System.err(11905): \tat org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)\r\n09-12 18:07:57.453: W/System.err(11905): \tat org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)\r\n09-12 18:07:57.463: W/System.err(11905): \tat org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)\r\n09-12 18:07:57.463: W/System.err(11905): \tat android.os.Handler.handleCallback(Handler.java:615)\r\n09-12 18:07:57.463: W/System.err(11905): \tat android.os.Handler.dispatchMessage(Handler.java:92)\r\n09-12 18:07:57.463: W/System.err(11905): \tat android.os.Looper.loop(Looper.java:137)\r\n09-12 18:07:57.463: W/System.err(11905): \tat org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)\r\n09-12 18:07:57.583: D/webviewglue(11905): nativeDestroy view: 0x56af02e0\r\n09-12 18:07:57.628: E/TiExceptionHandler(11905): (main) [111128,111432] ----- Titanium Javascript Runtime Error -----\r\n09-12 18:07:57.628: E/TiExceptionHandler(11905): (main) [3,111435] - In form.js:561,69\r\n09-12 18:07:57.628: E/TiExceptionHandler(11905): (main) [0,111435] - Message: Uncaught Error: Java Exception occurred\r\n09-12 18:07:57.628: E/TiExceptionHandler(11905): (main) [0,111435] - Source: photos[changeImage] = imagefactory.compress(e.media.imageAsRes\r\n09-12 18:07:57.843: W/ResourceType(11905): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)\r\n09-12 18:07:57.843: D/HardwareRenderer(11905): Profiling hardware renderer\r\n09-12 18:07:57.853: E/V8Exception(11905): Exception occurred at form.js:561: Uncaught Error: Java Exception occurred\r\n{code}\r\n\r\n\r\nAny ideas on how to solve it? (I really don't want to enable largeHeap on the Manifest for this.)", "attachment": [], "flagged": false, "summary": "Android: OutOFMemory Errors when using image compression, resizing or thumbnails on select devices like the Galaxy S2", "creator": { "name": "ygbr", "key": "ygbr", "displayName": "Ygor Lemos", "active": true, "timeZone": "America/Sao_Paulo" }, "subtasks": [], "reporter": { "name": "ygbr", "key": "ygbr", "displayName": "Ygor Lemos", "active": true, "timeZone": "America/Sao_Paulo" }, "environment": "Ti SDK 3.1.2.GA\r\nTested on Android 4.0 and 4.1\r\n", "comment": { "comments": [ { "id": "271439", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hi Ygor Lemos,\nCould you provide me full code so that i can reproduce this issue.\nThanks,", "updateAuthor": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2013-09-17T08:07:28.000+0000", "updated": "2013-09-17T08:07:28.000+0000" }, { "id": "271623", "author": { "name": "ygbr", "key": "ygbr", "displayName": "Ygor Lemos", "active": true, "timeZone": "America/Sao_Paulo" }, "body": "Hi Motiur,\n\nThe code is the one posted above... just compressing the image inside the success event of the showCamera gives the OutOfMemory error.\n\nI had to add \"android:largeHeap\" : \"true\" to the app AndroidManifest application tag in order for it to work properly on those devices...", "updateAuthor": { "name": "ygbr", "key": "ygbr", "displayName": "Ygor Lemos", "active": true, "timeZone": "America/Sao_Paulo" }, "created": "2013-09-17T23:49:07.000+0000", "updated": "2013-09-17T23:49:07.000+0000" }, { "id": "284360", "author": { "name": "mrahman", "key": "mrahman", "displayName": "Mostafizur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "We tried to reproduce this issue in-house with Titanium SDK 3.1.3.GA but were not able to reproduce. Please try this sample code and let us know if the issue persists.\r\n\r\nh5. Testing Environment:\r\nAndroid SDK: 4.2.2\r\nTitanium SDK: 3.1.3\r\nTitanium CLI Version: 3.1.2\r\n\r\n h5. Test Code\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor : '#000',\r\n\tlayout : 'vertical',\r\n\tnavBarHidden : false,\r\n\ttitle : 'Take a Photo From Camara'\r\n});\r\n \r\nvar takePhoto = Ti.UI.createButton({\r\n\ttitle : 'Take_Photo',\r\n\tcolor : '#000',\r\n\twidth : Ti.UI.SIZE,\r\n\theight : 60,\r\n\ttop : 10,\r\n});\r\n \r\nvar image = Ti.UI.createImageView({\r\n\ttop : 10,\r\n\theight : Ti.UI.SIZE,\r\n\twidth : Ti.UI.SIZE,\r\n});\r\n \r\nwin.add(takePhoto);\r\nwin.add(image);\r\n//win.add(anImageView);\r\ntakePhoto.addEventListener('click', function() {\r\n \r\n\tfireUpTheCamera();\r\n});\r\n \r\nfunction fireUpTheCamera() {\r\n\tTitanium.Media.showCamera({\r\n \r\n\t\tsuccess : function(event) {\r\n\t\t\tvar cropRect = event.cropRect;\r\n\t\t\tvar photo = event.media;\r\n \r\n\t\t\tTi.API.debug('Our type was: ' + event.mediaType);\r\n\t\t\tif (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {\r\n\t\t\t\tvar aspectRatio = photo.height / photo.width;\r\n \r\n\t\t\t\t//image.setImage(photo.imageAsThumbnail(129, 0, 0));\r\n\t\t\t\timage.setImage(photo.imageAsResized(640, 600 * aspectRatio), 0.5);\r\n \r\n\t\t\t} else {\r\n\t\t\t\talert(\"got the wrong type back =\" + event.mediaType);\r\n\t\t\t}\r\n\t\t},\r\n\t\tcancel : function() {\r\n\t\t},\r\n\t\terror : function(error) {\r\n\t\t\t// create alert\r\n\t\t\tvar a = Titanium.UI.createAlertDialog({\r\n\t\t\t\ttitle : 'Camera'\r\n\t\t\t});\r\n \r\n\t\t\t// set message\r\n\t\t\tif (error.code == Titanium.Media.NO_CAMERA) {\r\n\t\t\t\ta.setMessage('Please run this test on device');\r\n\t\t\t} else {\r\n\t\t\t\ta.setMessage('Unexpected error: ' + error.code);\r\n\t\t\t}\r\n \r\n\t\t\t// show alert\r\n\t\t\ta.show();\r\n\t\t},\r\n\t\tsaveToPhotoGallery : false,\r\n\t\tallowEditing : false,\r\n\t\tmediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]\r\n\t});\r\n}\r\n \r\nwin.open();\r\n{code}\r\n\r\n\r\nh5. Step to Test \r\n# Create a sample Project\r\n# Paste this code in app.js file\r\n# Click the button and successfully take a photo with imageAsResized or imageAsThumbnail without any crash.", "updateAuthor": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-15T13:40:29.000+0000", "updated": "2013-12-17T18:01:55.000+0000" }, { "id": "290132", "author": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing since we have not heard back from the reporter in a while.", "updateAuthor": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2014-01-29T00:09:08.000+0000", "updated": "2014-01-29T00:09:08.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }