Maybe use this code to load your texture?
public class Texture_Loader {
static public int get_texture(GL10 gl, Context context, int res_id) {
int[] texture_array = new int[1];
gl.glGenTextures(1, texture_array, 0);
int texture_id = texture_array[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture_id);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_REPEAT);
InputStream is = context.getResources().openRawResource(res_id);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
is.close();
} catch (IOException e) {
// Ignore.
}
}
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
return texture_id;
}
}
On Tuesday, August 24, 2010 11:04:29 AM UTC-5, Jason wrote:
>
> Hi all,
>
> I have posted previously on a related topic, but thought a new post
> with clearer descriptions may trigger someone out there with some
> knowledge.
>
> I am getting regular crashes in native (android) code when I am
> loading textures in opengl. Trace is:
>
> Build fingerprint: 'generic/sdk/generic/:1.6/Donut/20842:eng/test-
> keys'
> pid: 196, tid: 331 >>> com.cc.ra <<<
> signal 11 (SIGSEGV), fault addr 00000104
> r0 00000104 r1 000003d8 r2 00000104 r3 ac126bb8
> r4 00211f20 r5 00000100 r6 ac128344 r7 4251fe84
> r8 45d69da0 r9 4251fe7c 10 4251fe6c fp 00000001
> ip ac1285f4 sp 45d69d48 lr ac03ce10 pc afb04408 cpsr 20000010
> #00 pc 00004408 /system/lib/libcutils.so
> #01 lr ac03ce10 /system/lib/libsgl.so
> stack:
> 45d69d08 0015fab8 [heap]
> 45d69d0c 00000001
> 45d69d10 00000007
> 45d69d14 ad047361 /system/lib/libdvm.so
> 45d69d18 00000000
> 45d69d1c 0015fab8 [heap]
> 45d69d20 0033e650 [heap]
> 45d69d24 ad03dafb /system/lib/libdvm.so
> 45d69d28 ad083e1c /system/lib/libdvm.so
> 45d69d2c ad082c50 /system/lib/libdvm.so
> 45d69d30 ad03dadd /system/lib/libdvm.so
> 45d69d34 ad02e45b /system/lib/libdvm.so
> 45d69d38 0033e650 [heap]
> 45d69d3c 00211f20 [heap]
> 45d69d40 df002777
> 45d69d44 e3a070ad
> #00 45d69d48 00211f20 [heap]
> 45d69d4c ac03ce10 /system/lib/libsgl.so
> 45d69d50 ad336551 /system/lib/libandroid_runtime.so
> 45d69d54 0033e650 [heap]
> 45d69d58 00211f20 [heap]
> 45d69d5c ad349333 /system/lib/libandroid_runtime.so
> 45d69d60 00004000
> 45d69d64 00000000
> 45d69d68 00211f20 [heap]
> 45d69d6c 001e9ec8 [heap]
> 45d69d70 00000000
> 45d69d74 ac03cb30 /system/lib/libsgl.so
> 45d69d78 00000000
> 45d69d7c 001e9ec8 [heap]
> 45d69d80 00000000
> 45d69d84 ac03cb60 /system/lib/libsgl.so
> 45d69d88 45d69dc0
> 45d69d8c 00000000
>
> The failure always looks the same, but doesn't always happen at the
> same time.
>
> I am loading a GLSurfaceView in a fairly standard activity, however
> after several attempts I am now at the stage where in order to have an
> interim loading screen rendered over the top of the GLSurfaceView (for
> which I am using a ViewFlipper to flip to a standard Canvas-based
> view) I am needing to completely dissolve the GLSurfaceView every time
> a new "level" in the app (game) is loaded. (This is because I am not
> confident that simply flipping out the old view is causing the GL
> Context to be destroyed on all devices)
>
> When I try to create a new GLSurfaceView instance in the same
> activity, then load the textures, I get the above failure. As I said
> however, it doesn't always occur in the same place. That is,
> occasionally I will be able to play through several levels (GL setup &
> tear down events) without a problem, then at some point the failure
> will occur. It consistently fails, just not always immediately.
>
> When I tear down the GLSurfaceView (via a call to removeView on the
> ViewFlipper) I have verified that the surface is destroyed (hence
> previously loaded textures should be removed from vram) but no matter
> what sort of re-arranging of code I have tried I can't seem to avoid
> this failure.
>
> Happens on both the emulator, and device.
>
> No JNI warnings, and no GL failures reported when
> DEBUG_CHECK_GL_ERROR is enabled on the gl view.
>
> I really need some guidance on this. Does anyone have any clue as to
> how I can resolve, or even diagnose this?
>
> Thanks.
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en