diff --git a/src/native/common/arb/org_lwjgl_opengl_arb_ARBVertexBufferObject.cpp b/src/native/common/arb/org_lwjgl_opengl_arb_ARBVertexBufferObject.cpp index 141a5332..28229024 100644 --- a/src/native/common/arb/org_lwjgl_opengl_arb_ARBVertexBufferObject.cpp +++ b/src/native/common/arb/org_lwjgl_opengl_arb_ARBVertexBufferObject.cpp @@ -97,7 +97,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_arb_ARBVertexBufferObject_nglBuffer (JNIEnv * env, jclass clazz, jint target, jint size, jobject data, jint data_offset, jint usage) { CHECK_EXISTS(glBufferDataARB) - GLvoid *data_ptr = (GLvoid *)((GLubyte *)env->GetDirectBufferAddress(data) + data_offset); + GLvoid *data_ptr = (GLvoid *)safeGetBufferAddress(env, data, data_offset); glBufferDataARB(target, size, data_ptr, usage); CHECK_GL_ERROR } diff --git a/src/native/common/ati/org_lwjgl_opengl_ati_ATIVertexArrayObject.cpp b/src/native/common/ati/org_lwjgl_opengl_ati_ATIVertexArrayObject.cpp index e62c890a..ae63153e 100644 --- a/src/native/common/ati/org_lwjgl_opengl_ati_ATIVertexArrayObject.cpp +++ b/src/native/common/ati/org_lwjgl_opengl_ati_ATIVertexArrayObject.cpp @@ -46,7 +46,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_ati_ATIVertexArrayObject_nglNewObje (JNIEnv * env, jclass clazz, jint size, jobject pPointer, jint pPointer_offset, jint usage) { CHECK_EXISTS(glNewObjectBufferATI) - GLvoid *pPointer_ptr = (GLvoid *)((GLubyte *)env->GetDirectBufferAddress(pPointer) + pPointer_offset); + GLvoid *pPointer_ptr = safeGetBufferAddress(env, pPointer, pPointer_offset); GLuint result = glNewObjectBufferATI(size, pPointer_ptr, usage); CHECK_GL_ERROR return result; diff --git a/src/native/common/common_tools.h b/src/native/common/common_tools.h index db371130..a4748163 100644 --- a/src/native/common/common_tools.h +++ b/src/native/common/common_tools.h @@ -67,11 +67,11 @@ extern void throwOpenALException(JNIEnv * env, const char * err); extern void setDebugEnabled(bool enable); extern void printfDebug(const char *format, ...); -static inline void * safeGetBufferAddress(JNIEnv *env, jobject buffer) { +static inline void * safeGetBufferAddress(JNIEnv *env, jobject buffer, int offset) { if (buffer == NULL) return NULL; else - return env->GetDirectBufferAddress(buffer); + return (void *)((char *)env->GetDirectBufferAddress(buffer) + offset); } static inline jobject safeNewBuffer(JNIEnv *env, void *p, int size) {