Note that there are some explanatory texts on larger screens.

plurals
  1. POOutOfMemory Exception android OpenGLes LoadTextures
    primarykey
    data
    text
    <p>I'm trying to load my textures in order to use them in my game. for now, my game needs 84 image frames in order to work as I expect, but when I load this much of images, it gives me OutOfMemmory Exception.</p> <p>Is there any better way to load these images? </p> <p>Obs each one of them have 150x150px on HDPI devices.</p> <p>the device i'm running it is an Galaxy SII witch I believe has 50mb of heap memory. </p> <p>Here's where the exception occurs:</p> <pre><code> public void loadTextures(GL10 gl) { InputStream is[] = new InputStream[textureCount]; Bitmap bitmap[] = new Bitmap[textureCount]; is[0] = context.getResources().openRawResource(R.drawable.bg_01); is[1] = context.getResources().openRawResource(R.drawable.bg_02); is[2] = context.getResources().openRawResource(R.drawable.bg_03); is[3] = context.getResources().openRawResource(R.drawable.win_hud); is[4] = context.getResources().openRawResource(R.drawable.heart); is[5] = context.getResources().openRawResource(R.drawable.skyblue); is[6] = context.getResources().openRawResource(R.drawable.heart); is[7] = context.getResources().openRawResource(R.drawable.heart); is[8] = context.getResources().openRawResource(R.drawable.heart); is[9] = context.getResources().openRawResource(R.drawable.heart); is[10] = context.getResources().openRawResource(R.drawable.heart); //reserving numbers for more textures from 6 to 10. is[11] = context.getResources().openRawResource(R.drawable.walking01); is[12] = context.getResources().openRawResource(R.drawable.walking02); is[13] = context.getResources().openRawResource(R.drawable.walking03); is[14] = context.getResources().openRawResource(R.drawable.walking04); is[15] = context.getResources().openRawResource(R.drawable.walking05); is[16] = context.getResources().openRawResource(R.drawable.flying01); is[17] = context.getResources().openRawResource(R.drawable.flying02); is[18] = context.getResources().openRawResource(R.drawable.falling_01); is[19] = context.getResources().openRawResource(R.drawable.falling_02); is[20] = context.getResources().openRawResource(R.drawable.fallen); is[21] = context.getResources().openRawResource( R.drawable.standingup_01); is[22] = context.getResources().openRawResource( R.drawable.standingup_02); is[23] = context.getResources().openRawResource(R.drawable.death_01); is[24] = context.getResources().openRawResource(R.drawable.death_02); is[25] = context.getResources().openRawResource(R.drawable.death_03); is[26] = context.getResources().openRawResource(R.drawable.death_04); is[27] = context.getResources().openRawResource(R.drawable.death_05); is[28] = context.getResources().openRawResource(R.drawable.death_06); is[29] = context.getResources().openRawResource(R.drawable.p_walk_1); is[30] = context.getResources().openRawResource(R.drawable.p_walk_2); is[31] = context.getResources().openRawResource(R.drawable.p_walk_3); is[32] = context.getResources().openRawResource(R.drawable.p_walk_4); is[33] = context.getResources().openRawResource(R.drawable.p_walk_5); is[34] = context.getResources().openRawResource(R.drawable.p_walk_6); is[35] = context.getResources().openRawResource(R.drawable.p_holding01); is[36] = context.getResources().openRawResource(R.drawable.p_holding03); is[37] = context.getResources().openRawResource(R.drawable.p_opening01); is[38] = context.getResources().openRawResource(R.drawable.p_opening02); is[39] = context.getResources().openRawResource(R.drawable.p_parachute01); is[40] = context.getResources().openRawResource(R.drawable.p_parachute02); is[41] = context.getResources().openRawResource(R.drawable.p_parachute03); is[42] = context.getResources().openRawResource(R.drawable.p_parachute04); is[43] = context.getResources().openRawResource(R.drawable.p_parachute05); is[44] = context.getResources().openRawResource(R.drawable.p_closing01); is[45] = context.getResources().openRawResource(R.drawable.p_closing02); is[46] = context.getResources().openRawResource(R.drawable.p_cracking01); is[47] = context.getResources().openRawResource(R.drawable.p_cracking02); is[48] = context.getResources().openRawResource(R.drawable.p_fallen01); is[49] = context.getResources().openRawResource(R.drawable.p_standing01); is[50] = context.getResources().openRawResource(R.drawable.p_standing02); is[51] = context.getResources().openRawResource(R.drawable.p_standing3); is[52] = context.getResources().openRawResource(R.drawable.p_dead01); is[53] = context.getResources().openRawResource(R.drawable.p_dead02); is[54] = context.getResources().openRawResource(R.drawable.p_dead03); is[55] = context.getResources().openRawResource(R.drawable.p_dead04); is[56] = context.getResources().openRawResource(R.drawable.p_dead05); is[57] = context.getResources().openRawResource(R.drawable.p_dead06); is[58] = context.getResources().openRawResource(R.drawable.p_dead07); is[59] = context.getResources().openRawResource(R.drawable.p_dead08); is[60] = context.getResources().openRawResource(R.drawable.p_dead09); is[61] = context.getResources().openRawResource(R.drawable.r_walking01); is[62] = context.getResources().openRawResource(R.drawable.r_walking02); is[63] = context.getResources().openRawResource(R.drawable.r_walking03); is[64] = context.getResources().openRawResource(R.drawable.r_walking04); is[65] = context.getResources().openRawResource(R.drawable.r_walking05); is[66] = context.getResources().openRawResource(R.drawable.r_walking06); is[67] = context.getResources().openRawResource(R.drawable.r_walking07); is[68] = context.getResources().openRawResource(R.drawable.r_walking08); is[69] = context.getResources().openRawResource(R.drawable.r_falling01); is[70] = context.getResources().openRawResource(R.drawable.r_falling02); is[71] = context.getResources().openRawResource(R.drawable.r_fallen); is[72] = context.getResources().openRawResource(R.drawable.r_standingup01); is[73] = context.getResources().openRawResource(R.drawable.r_standingup02); is[74] = context.getResources().openRawResource(R.drawable.r_dyeing01); is[75] = context.getResources().openRawResource(R.drawable.r_dyeing02); is[76] = context.getResources().openRawResource(R.drawable.r_dyeing03); is[77] = context.getResources().openRawResource(R.drawable.r_dyeing04); is[78] = context.getResources().openRawResource(R.drawable.r_dyeing05); is[79] = context.getResources().openRawResource(R.drawable.r_dyeing06); is[80] = context.getResources().openRawResource(R.drawable.r_dyeing07); is[81] = context.getResources().openRawResource(R.drawable.r_dyeing08); is[82] = context.getResources().openRawResource(R.drawable.r_dyeing09); is[83] = context.getResources().openRawResource(R.drawable.r_dyeing10); for (int loop = 0; loop &lt; textureCount; loop++) { bitmap[loop] = BitmapFactory.decodeStream(is[loop]); try { is[loop].close(); is[loop] = null; } catch (IOException e) { } } gl.glGenTextures(textureCount, textures, 0); for (int loop = 0; loop &lt; textureCount; loop++) { gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[loop]); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, // OpenGL docs. GL10.GL_NICEST); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap[loop], 0); bitmap[loop].recycle(); } } </code></pre>
    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.
 

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