From d5bfe10379d482e823ab2f70e9d5c51b0b128aee Mon Sep 17 00:00:00 2001 From: minggo Date: Sat, 8 Jun 2013 16:58:18 +0800 Subject: [PATCH] fixed #2161: fixed crash of loading ETC file --- .../src/org/cocos2dx/lib/Cocos2dxETCLoader.java | 13 ++++++++----- cocos2dx/textures/CCTextureETC.cpp | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxETCLoader.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxETCLoader.java index c9dbf435e0..fd4cd81954 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxETCLoader.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxETCLoader.java @@ -75,17 +75,19 @@ public class Cocos2dxETCLoader { boolean ret = true; try { - int width = texture.getWidth(); - int height = texture.getHeight(); + final int width = texture.getWidth(); + final int height = texture.getHeight(); + final int length = texture.getData().remaining(); - final byte[] data = new byte[width * height * 3]; + final byte[] data = new byte[length]; final ByteBuffer buf = ByteBuffer.wrap(data); buf.order(ByteOrder.nativeOrder()); buf.put(texture.getData()); nativeSetTextureInfo(width, height, - data); + data, + length); } catch (Exception e) { Log.d("invoke native function error", e.toString()); @@ -102,5 +104,6 @@ public class Cocos2dxETCLoader { Cocos2dxETCLoader.context = context; } - private static native void nativeSetTextureInfo(final int width, final int height, final byte[] data); + private static native void nativeSetTextureInfo(final int width, final int height, final byte[] data, + final int dataLength); } diff --git a/cocos2dx/textures/CCTextureETC.cpp b/cocos2dx/textures/CCTextureETC.cpp index a6189aa19b..bd3464b408 100644 --- a/cocos2dx/textures/CCTextureETC.cpp +++ b/cocos2dx/textures/CCTextureETC.cpp @@ -81,11 +81,11 @@ static unsigned int sLength = 0; extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxETCLoader_nativeSetTextureInfo(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray data) + JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxETCLoader_nativeSetTextureInfo(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray data, jint dataLength) { sWidth = (unsigned int)width; sHeight = (unsigned int)height; - sLength = sWidth * sHeight * 3; + sLength = dataLength; sData = new unsigned char[sLength]; env->GetByteArrayRegion(data, 0, sLength, (jbyte*)sData); }