fixed #2161: fixed crash of loading ETC file

This commit is contained in:
minggo 2013-06-08 16:58:18 +08:00
parent f56c20657b
commit d5bfe10379
2 changed files with 10 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);
}