-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Labels
Description
BufferUtils.copy (byte[] src, int srcOffset, Buffer dst, int numElements)
works fine on Desktop, but fails on GWT.
How to reproduce:
- Run this test on Desktop and on GWT
package com.badlogic.gdx.tests.gwt;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.utils.BufferUtils;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.reflect.ClassReflection;
public class BufferUtilsIssueTest extends GdxTest {
// Needed to make the test work on gwt _and_ desktop
private ByteBuffer getTestBuffer (int size) {
if (Gdx.app.getType().equals(ApplicationType.WebGL)) {
return BufferUtils.newByteBuffer(size);
} else {
com.badlogic.gdx.utils.reflect.Method bufferMethod = null;
try {
bufferMethod = ClassReflection.getMethod(BufferUtils.class, "newUnsafeByteBuffer", int.class);
return (ByteBuffer)bufferMethod.invoke(null, size);
} catch (Exception e) { // Who cares!
e.printStackTrace();
}
}
return null;
}
@Override
public void create () {
final ByteBuffer newByteBuffer = getTestBuffer(10);
final byte[] src = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
BufferUtils.copy(src, 0, newByteBuffer, 2);
BufferUtils.copy(src, 2, newByteBuffer, 4);
}
}
I get the following stack trace on GWT:
Throwable.java:121 Uncaught Error: java.nio.BufferOverflowException
at P3k_g$.BQd_g$ [as createError_0_g$] (Throwable.java:121)
at P3k_g$.LQd_g$ [as initializeBackingError_0_g$] (Throwable.java:113)
at P3k_g$.sQd_g$ (Throwable.java:61)
at P3k_g$.YQd_g$ (Exception.java:25)
at P3k_g$.eRd_g$ (RuntimeException.java:25)
at P3k_g$ (BufferOverflowException.java:31)
at P8k_g$.d9k_g$ [as put_17_g$] (DirectReadWriteByteBuffer.java:132)
at ZNd_g$ (BufferUtils.java:75)
at qan_g$.ran_g$ [as create_0_g$] (BufferUtilsIssueTest.java:39)
at BHd_g$.CHd_g$ [as clicked_0_g$] (GwtTestWrapper.java:155)
at BHd_g$.UMc_g$ [as touchUp_3_g$] (ClickListener.java:89)
at BHd_g$.pBc_g$ [as handle_3_g$] (InputListener.java:58)
at ABc_g$.CCc_g$ [as touchUp_1_g$] (Stage.java:353)
at cc_g$.tc_g$ [as touchUp_1_g$] (InputMultiplexer.java:96)
at Fu_g$.ov_g$ [as handleEvent_0_g$] (GwtInput.java:564)
at HTMLDocument.<anonymous> (GwtInput.java:405)