mirror of https://github.com/axmolengine/axmol.git
fixed #2161: fixed crash of loading ETC file
This commit is contained in:
parent
f56c20657b
commit
d5bfe10379
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue