diff --git a/src/java/org/lwjgl/PointerBuffer.java b/src/java/org/lwjgl/PointerBuffer.java index 7938d093..c1a02b9a 100644 --- a/src/java/org/lwjgl/PointerBuffer.java +++ b/src/java/org/lwjgl/PointerBuffer.java @@ -80,12 +80,8 @@ public class PointerBuffer implements Comparable { * @param source the source buffer */ public PointerBuffer(final ByteBuffer source) { - if ( !source.isDirect() ) - throw new IllegalArgumentException("ByteBuffer is not direct"); - - final int alignment = is64Bit ? 8 : 4; - if ( (BufferUtils.getBufferAddress(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 ) - throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes."); + if ( LWJGLUtil.CHECKS ) + checkSource(source); pointers = source.slice().order(source.order()); @@ -98,6 +94,15 @@ public class PointerBuffer implements Comparable { } } + private static void checkSource(final ByteBuffer source) { + if ( !source.isDirect() ) + throw new IllegalArgumentException("The source buffer is not direct."); + + final int alignment = is64Bit ? 8 : 4; + if ( (BufferUtils.getBufferAddress(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 ) + throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes."); + } + /** * Returns the ByteBuffer that backs this PointerBuffer. * diff --git a/src/native/common/org_lwjgl_BufferUtils.c b/src/native/common/org_lwjgl_BufferUtils.c index cf7cd12e..be80123c 100644 --- a/src/native/common/org_lwjgl_BufferUtils.c +++ b/src/native/common/org_lwjgl_BufferUtils.c @@ -1,4 +1,5 @@ #include "org_lwjgl_BufferUtils.h" +#include "common_tools.h" JNIEXPORT void JNICALL Java_org_lwjgl_BufferUtils_zeroBuffer0(JNIEnv *env, jclass clazz, jobject buffer, jlong offset, jlong size) { memset((char*)(*env)->GetDirectBufferAddress(env, buffer) + (size_t)offset, 0, (size_t)size); @@ -6,4 +7,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_BufferUtils_zeroBuffer0(JNIEnv *env, jclas JNIEXPORT jlong JNICALL Java_org_lwjgl_BufferUtils_getBufferAddress(JNIEnv *env, jclass clazz, jobject buffer) { return (intptr_t)(*env)->GetDirectBufferAddress(env, buffer); -} \ No newline at end of file +}