Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2313] Android: bitmaps fetched by resource id more susceptible to out-of-memory errors

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:58:44.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, defect
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:16:27.000+0000
Updated2011-04-17T01:58:44.000+0000

Description

Our internal code that loads bitmaps using resource ids does not have the protection afforded by using certain BitmapFactory.Options which we use when loading the bitmaps by url (instead of resource id). This was an oversight.

Failcase:

Put the attached PNG into Resources/android/images/medium, then run this app.js:

/*global Ti, Titanium, alert, JSON */
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({  
    title:'Test',
    backgroundColor:'#fff',
    fullscreen: true,
    exitOnClose: true
});
win.open();

var tv = Ti.UI.createTableView();
var i = 0;
win.add(tv);

var images = [];
for (i = 0; i < 25; i++) {
    images.push('images/test.png');
}

for (i = 0 ; i < 50; i++) {
    var tr = Ti.UI.createTableViewRow();
    tr.add(
        Ti.UI.createImageView({images: images})
    );
    tv.appendRow(tr);
}

The app should crash and if you look at the logcat you should see similar to:

E/AndroidRuntime(  450): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(  450):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(  450):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:447)
E/AndroidRuntime(  450):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
E/AndroidRuntime(  450):    at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
E/AndroidRuntime(  450):    at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
E/AndroidRuntime(  450):    at org.appcelerator.titanium.util.TiUIHelper.getResourceBitmap(TiUIHelper.java:543)
E/AndroidRuntime(  450):    at ti.modules.titanium.ui.widget.TiUIImageView.createBitmap(TiUIImageView.java:137)
E/AndroidRuntime(  450):    at ti.modules.titanium.ui.widget.TiUIImageView$Loader.run(TiUIImageView.java:268)
E/AndroidRuntime(  450):    at java.lang.Thread.run(Thread.java:1096)

Attachments

FileDateSize
test.png2011-04-15T03:16:27.000+00005043

Comments

  1. Bill Dawson 2011-04-15

    (from [dad7bc94565a627a14323e5b08ad5a562724fcbf]) [#2313 state:fixed-in-qa] Use BitmapFactory.Options options to help avoid OOM errors loading bitmaps by resource id https://github.com/appcelerator/titanium_mobile/commit/dad7bc94565a627a14323e5b08ad5a562724fcbf"> https://github.com/appcelerator/titanium_mobile/commit/dad7bc94565a...

  2. Bill Dawson 2011-04-15

    (from [5e35a4041f17c7cb0a71190ba4a79547315fc910]) [#2313 state:fixed-in-qa] Use BitmapFactory.Options options to help avoid OOM errors loading bitmaps by resource id https://github.com/appcelerator/titanium_mobile/commit/5e35a4041f17c7cb0a71190ba4a79547315fc910"> https://github.com/appcelerator/titanium_mobile/commit/5e35a4041f17...

  3. Bill Dawson 2011-04-15

    (from [7ff8c90985b6d922ffe46e0d2e12b22c434f06dd]) [#2313 state:fixed-in-qa] add drillbit https://github.com/appcelerator/titanium_mobile/commit/7ff8c90985b6d922ffe46e0d2e12b22c434f06dd"> https://github.com/appcelerator/titanium_mobile/commit/7ff8c90985b6...

  4. Matt Schmulen 2011-04-15

    Pass Titanium SDK version: 1.5.0 (12/01/10 09:30 ac7cfd8) drillbit test Android Sim 1.6/2.1

    android sim 1.6
    https://5111068499667359260-a-appcelerator-com-s-sites.googlegroups.com/a/appcelerator.com/android/screenshots/Screenshot2010-12-02at2.30.47AM.png?attachauth=ANoY7crKsfvMfdez3l27wnG_vOB0igXOd2AW8GVzP33R4KO4JNDSdg0wYeWx8OR34RLcQs0pfHxUiuoIsoVb5OClouqEI_CmWLRvbhD64WJg7KiGw4U6-679XjvXSqApaVCVyGqDjjfcHnceQepDqw0Wky44GDYZpomldZ1mAY0K0qqkI_BWhN2ETrFqCIPUjsjX6ZtLnuIJ5H1eYOg2P-M9OoYJKY6_TozjeA9AGUlbA3qoW-OTVh0%3D&;attredirects=0"> https://5111068499667359260-a-appcelerator-com-s-sites.googlegroups...

    android sim 2.1
    https://5111068499667359260-a-appcelerator-com-s-sites.googlegroups.com/a/appcelerator.com/android/screenshots/Screenshot2010-12-02at2.48.13AM.png?attachauth=ANoY7cqZMHs0_-0NFdd52s4sE13MK769EMBj1VEL9mkQdyPJ_1Lylg56ioZ3EKIhrSl7RMoVTCAI9cY4-jfDs6mOqdJOyP9mQrY28Zjh5vBQGQ6_377a21CU3cn9Al6-wi8damB2gpx5waY3FoILV9l9iIqifi6D5Jue3Rbig8yVLAwmls-q_qLFApWfmRmL9V7zuCx18cVF9-Om9uMmhzz7EKdEBj6cJ1MuzGF5vuOn6vTnexNmgr0%3D&;attredirects=0"> https://5111068499667359260-a-appcelerator-com-s-sites.googlegroups...

JSON Source