Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2611] Trying to create an image from thumbnail on Android, crashes the app on some devices.

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2013-04-30T23:38:43.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsimageView, media, showcamera, thumbnail
ReporterYgor Lemos
AssigneeShak Hossain
Created2013-04-30T22:44:45.000+0000
Updated2016-03-08T07:41:41.000+0000

Description

This crashes on the Motorola Razr running Android 4.0.4, but runs OK on a Samsung Galaxy Y running Android 2.3.6 and on a Galaxy S3 running 4.1.2. The code snippet is the following:
iv = Ti.UI.createImageView();


var takePhoto = Ti.UI.createButton({
                title:"Take Photo",
                width: 129,
                height: 44,
                top: 80,
                left: 25,
                idx: i
            }, function(){
                Ti.Media.showCamera({
    				allowEditing: false,
    				mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO,
    				saveToPhotoGallery: false,
    				success: function(e){
						iv.setImage(e.media.imageAsThumbnail(129, 0, 0));
						
    				},
					error: function(e) {
						alert(e);
					}
    			});
            });
Here is the output on logcat monitor with the full crash path:
04-30 19:35:53.270: D/dalvikvm(13250): GC_FOR_ALLOC freed 542K, 25% free 15615K/20707K, paused 49ms
04-30 19:35:53.270: I/dalvikvm-heap(13250): Forcing collection of SoftReferences for 31961104-byte allocation
04-30 19:35:53.340: D/dalvikvm(13250): GC_BEFORE_OOM freed 0K, 25% free 15615K/20707K, paused 68ms
04-30 19:35:53.340: E/dalvikvm-heap(13250): Out of memory on a 31961104-byte allocation.
04-30 19:35:53.340: I/dalvikvm(13250): "KrollRuntimeThread" prio=5 tid=11 RUNNABLE
04-30 19:35:53.340: I/dalvikvm(13250):   | group="main" sCount=0 dsCount=0 obj=0x41500870 self=0x21051f0
04-30 19:35:53.340: I/dalvikvm(13250):   | sysTid=13266 nice=0 sched=0/0 cgrp=default handle=34716648
04-30 19:35:53.340: I/dalvikvm(13250):   | schedstat=( 0 0 0 ) utm=298 stm=48 core=1
04-30 19:35:53.340: I/dalvikvm(13250):   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-30 19:35:53.340: I/dalvikvm(13250):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:530)
04-30 19:35:53.340: I/dalvikvm(13250):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:586)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.titanium.TiBlob.getImage(TiBlob.java:492)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.titanium.TiBlob.imageAsThumbnail(TiBlob.java:540)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)
04-30 19:35:53.340: I/dalvikvm(13250):   at android.os.Handler.handleCallback(Handler.java:605)
04-30 19:35:53.340: I/dalvikvm(13250):   at android.os.Handler.dispatchMessage(Handler.java:92)
04-30 19:35:53.340: I/dalvikvm(13250):   at android.os.Looper.loop(Looper.java:137)
04-30 19:35:53.340: I/dalvikvm(13250):   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
04-30 19:35:53.340: D/skia(13250): --- decoder->decode returned false
04-30 19:35:53.340: W/System.err(13250): java.lang.OutOfMemoryError
04-30 19:35:53.348: W/System.err(13250): 	at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-30 19:35:53.348: W/System.err(13250): 	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:530)
04-30 19:35:53.348: W/System.err(13250): 	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:586)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.titanium.TiBlob.getImage(TiBlob.java:492)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.titanium.TiBlob.imageAsThumbnail(TiBlob.java:540)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
04-30 19:35:53.348: W/System.err(13250): 	at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)
04-30 19:35:53.348: W/System.err(13250): 	at android.os.Handler.handleCallback(Handler.java:605)
04-30 19:35:53.356: W/System.err(13250): 	at android.os.Handler.dispatchMessage(Handler.java:92)
04-30 19:35:53.356: W/System.err(13250): 	at android.os.Looper.loop(Looper.java:137)
04-30 19:35:53.356: W/System.err(13250): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
04-30 19:35:53.512: E/TiExceptionHandler(13250): (main) [187280,278564] ----- Titanium Javascript Runtime Error -----
04-30 19:35:53.512: E/TiExceptionHandler(13250): (main) [0,278564] - In form.js:408,49
04-30 19:35:53.512: E/TiExceptionHandler(13250): (main) [0,278564] - Message: Uncaught Error: Java Exception occurred
04-30 19:35:53.512: E/TiExceptionHandler(13250): (main) [0,278564] - Source: 						placeholder[changeImage].setImage(e.media.imageAsThumbnail(129, 0, 0));
04-30 19:35:53.535: E/V8Exception(13250): Exception occurred at form.js:408: Uncaught Error: Java Exception occurred

Comments

  1. Carter Lathrop 2013-04-30

    Hello Ygor, When submitting a bug report it is important that you provide a working test case that is able to be easily pasted into an app.js and when run, clearly shows the problem. This ensures a speedy review and thorough understanding of the problem on both sides. Would you mind editing the bug description to provide this test case? For future reference: https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report Regards, Carter
  2. Ygor Lemos 2013-05-02

    Hi Carter, I have asked one of our Android Engineers for elaborating the test case as he is with the device right now. I've just filled the bug report earlier as I had a stack trace and the bug is happening only on certain devices. Daniel will attach a test case soon.
  3. Daniel Hansson 2013-05-02

    Hi Carter, Here is a working test case with the problem. {noformat} var w = Ti.UI.createWindow({ backgroundColor: "#dddcdc", navBarHidden: true, fullscreen: false, orientationModes: [Ti.UI.PORTRAIT] }); var rows = []; //PHOTOS var photos = [], placeholder = [], changeImage = false; for (var i=0, item; i<1; i++) { var r = Ti.UI.createTableViewRow({ backgroundImage: "img/form/photo.png", height: 187, width: 320, className: "rowPhoto" }); placeholder[i] = Ti.UI.createView({ backgroundColor: "#ccc", width: 129, height: 95, top: 60, right: 25, zIndex: 5, autorotate: true, borderRadius:10 }); r.add(placeholder[i]); var takePhoto = Ti.UI.createButton({ title: "TAKE PHOTO", width: 129, height: 129, top: 60, left: 25, idx: i }); r.add(takePhoto); takePhoto.addEventListener("click", function(e){ changeImage = this.idx; Ti.Media.showCamera({ allowEditing: false, mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO, saveToPhotoGallery: false, success: function(e){ placeholder[changeImage].setImage(e.media.imageAsThumbnail(129, 0, 0)); }, error: function(e) { alert(e); } }); }); rows.push(r); } var t = Ti.UI.createTableView({ backgroundColor: 'transparent', data: rows }); w.add(t); w.open(); {noformat} Thanks in advance Daniel Hansson
  4. Mostafizur Rahman 2013-12-10

    We tried to reproduce this issue but were not able to reproduce with Titanium SDK 3.1.3GA. Please test your application with the sample code and let us know if the problem persists.

    Testing Environment:

    Ti CLI 3.3.0 Titanium SDK: 3.1.3 and later Android SDK 2.3.3, 4.2.2

    Test Code

       var win = Ti.UI.createWindow({
       	backgroundColor : '#000',
       	layout : 'vertical',
       	navBarHidden : false,
       	title : 'Take a Photo From Camara'
       });
       
       var takePhoto = Ti.UI.createButton({
       	title : 'Take_Photo',
       	color : '#000',
       	width : Ti.UI.SIZE,
       	height : 60,
       	top : 10,
       });
       
       var image = Ti.UI.createImageView({
       	top : 10,
       	height : Ti.UI.SIZE,
       	width : Ti.UI.SIZE,
       });
       
       win.add(takePhoto);
       win.add(image); 
       takePhoto.addEventListener('click', function() {
       
       	fireUpTheCamera();
       });
       
       function fireUpTheCamera() {
       	Titanium.Media.showCamera({
       
       		success : function(event) {
       			var cropRect = event.cropRect;
       			var photo = event.media;
       
       			Ti.API.debug('Our type was: ' + event.mediaType);
       			if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
       				image.setImage(photo.imageAsThumbnail(129, 0, 0));
       
       			} else {
       				alert("got the wrong type back =" + event.mediaType);
       			}
       		},
       		cancel : function() {
       		},
       		error : function(error) {
       			alert('Unexpected error: ' + error.code);
       		},
       		saveToPhotoGallery : false,
       		allowEditing : false,
       		mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
       	});
       }
       
       win.open();
       
       

JSON Source