Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen loading bitmap with "BitmapFactory.decodeResource" app crashes
    primarykey
    data
    text
    <p>I'm developing a game for little children, which contains different educative exercises. In one of them I need a picture background, so I'm loading it and scale it with Matrix to fill screen. But sometimes loading picture causes crash.</p> <pre><code>public DrawThread(SurfaceHolder surfaceHolder, Resources resources, float screen_x_max, float screen_y_max){ this.surfaceHolder = surfaceHolder; screenWidth=screen_x_max; screenHeight=screen_y_max; // picture for bg picture = BitmapFactory.decodeResource(resources, R.drawable.background); ... } </code></pre> <p>At the end of this thread I recycle it and null.</p> <pre><code>if (this.picture!=null) { this.picture.recycle(); this.picture=null; } </code></pre> <p>But app still crases. There is error log:</p> <pre><code>java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:494) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:370) at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:393) at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:419) at lexu.me.childstudy_lite.DrawThreadFindAnimals2.&lt;init&gt;(findAnimals2.java:271) at lexu.me.childstudy_lite.findanimals2_view.surfaceCreated(findAnimals2.java:186) at android.view.SurfaceView.updateWindow(SurfaceView.java:548) at android.view.SurfaceView.dispatchDraw(SurfaceView.java:353) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466) at android.view.ViewGroup.drawChild(ViewGroup.java:1737) </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload