diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 7d446484..91f2468c 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -47,6 +47,8 @@ import org.lwjgl.input.Mouse; * @version $Revision$ */ public final class Sys { + public static final String VERSION = "0.9pre"; + /** Low process priority. @see #setProcessPriority() */ public static final int LOW_PRIORITY = -1; @@ -78,9 +80,9 @@ public final class Sys { /** The native library name */ private static String LIBRARY_NAME = "lwjgl"; - - /** The platform being executed on */ - private static String PLATFORM; + + /** The platform being executed on */ + private static String PLATFORM; /** * Debug flag. @@ -91,12 +93,6 @@ public final class Sys { static { initialize(); - - // check platform name, and default to awt - PLATFORM = System.getProperty("org.lwjgl.Sys.platform"); - if(PLATFORM == null) { - PLATFORM = "org.lwjgl.SwingAdapter"; - } } /** @@ -130,9 +126,19 @@ public final class Sys { return; initialized = true; System.loadLibrary(LIBRARY_NAME); + String native_version = getNativeLibraryVersion(); + if (!native_version.equals(VERSION)) + throw new IllegalStateException("Version mismatch: jar version is '" + VERSION + + "', native libary version is '" + native_version + "'"); setDebug(DEBUG); setTime(0); + // check platform name, and default to awt + PLATFORM = System.getProperty("org.lwjgl.Sys.platform"); + if(PLATFORM == null) { + PLATFORM = "org.lwjgl.SwingAdapter"; + } + Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { Display.resetDisplayMode(); @@ -148,7 +154,12 @@ public final class Sys { } /** - * Set the debug level of the native library + * Return the version of the native library + */ + private static native String getNativeLibraryVersion(); + + /** + * Set the debug level of the native library */ private static native void setDebug(boolean debug); diff --git a/src/native/common/checkALerror.h b/src/native/common/checkALerror.h index 1cacc2b9..3c02e894 100644 --- a/src/native/common/checkALerror.h +++ b/src/native/common/checkALerror.h @@ -16,7 +16,7 @@ #define CHECK_AL_ERROR \ { \ - if (ISDEBUGENABLED()) { \ + if (isDebugEnabled()) { \ int err = alGetError(); \ if (err != AL_NO_ERROR) { \ jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \ @@ -28,7 +28,7 @@ /* only available if deviceaddress is specified in method */ #define CHECK_ALC_ERROR \ { \ - if (ISDEBUGENABLED()) { \ + if (isDebugEnabled()) { \ int err = alcGetError((ALCdevice*) deviceaddress); \ if (err != AL_NO_ERROR) { \ jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \ diff --git a/src/native/common/common_tools.cpp b/src/native/common/common_tools.cpp index 794dd4d7..8b77f6a6 100644 --- a/src/native/common/common_tools.cpp +++ b/src/native/common/common_tools.cpp @@ -40,7 +40,16 @@ #include #include "common_tools.h" -bool debug = false; +static bool debug = false; +static const char* VERSION = "0.9pre"; + +jstring getVersionString(JNIEnv *env) { + return env->NewStringUTF(VERSION); +} + +bool isDebugEnabled(void) { + return debug; +} void setDebugEnabled(bool enable) { debug = enable; @@ -49,7 +58,7 @@ void setDebugEnabled(bool enable) { void printfDebug(const char *format, ...) { va_list ap; va_start(ap, format); - if (ISDEBUGENABLED()) + if (isDebugEnabled()) vfprintf(stderr, format, ap); va_end(ap); } diff --git a/src/native/common/common_tools.h b/src/native/common/common_tools.h index 5b103cad..0c04e537 100644 --- a/src/native/common/common_tools.h +++ b/src/native/common/common_tools.h @@ -43,11 +43,8 @@ #include #include "org_lwjgl_Sys.h" -extern bool debug; - // Must be x * max_event_size + 1 #define EVENT_BUFFER_SIZE (25 * 4 + 1) -#define ISDEBUGENABLED() (debug) typedef struct { unsigned char input_event_buffer[EVENT_BUFFER_SIZE]; @@ -56,6 +53,8 @@ typedef struct { int list_end; } event_queue_t; +extern bool isDebugEnabled(void); +extern jstring getVersionString(JNIEnv *env); extern void initEventQueue(event_queue_t *event_queue); extern int copyEvents(event_queue_t *event_queue, unsigned char *output_event_buffer, int buffer_size, int event_size); extern void putEventElement(event_queue_t *queue, unsigned char byte); diff --git a/src/native/common/org_lwjgl_Sys.h b/src/native/common/org_lwjgl_Sys.h index e7e5020a..f1830088 100644 --- a/src/native/common/org_lwjgl_Sys.h +++ b/src/native/common/org_lwjgl_Sys.h @@ -16,7 +16,17 @@ extern "C" { #undef org_lwjgl_Sys_REALTIME_PRIORITY #define org_lwjgl_Sys_REALTIME_PRIORITY 2L /* Inaccessible static: LIBRARY_NAME */ +/* Inaccessible static: PLATFORM */ /* Inaccessible static: DEBUG */ +/* Inaccessible static: initialized */ +/* + * Class: org_lwjgl_Sys + * Method: getNativeLibraryVersion + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion + (JNIEnv *, jclass); + /* * Class: org_lwjgl_Sys * Method: setDebug diff --git a/src/native/linux/org_lwjgl_Sys.cpp b/src/native/linux/org_lwjgl_Sys.cpp index 9f568dd3..1557d545 100644 --- a/src/native/linux/org_lwjgl_Sys.cpp +++ b/src/native/linux/org_lwjgl_Sys.cpp @@ -165,6 +165,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jst env->ReleaseStringUTFChars(title, cTitleBarText); } +JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) { + return getVersionString(env); +} + /* * Class: org_lwjgl_Sys * Method: openURL diff --git a/src/native/linux/org_lwjgl_opengl_Window.cpp b/src/native/linux/org_lwjgl_opengl_Window.cpp index f6c348a8..91e09d7c 100644 --- a/src/native/linux/org_lwjgl_opengl_Window.cpp +++ b/src/native/linux/org_lwjgl_opengl_Window.cpp @@ -420,7 +420,7 @@ static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring titl createWindow(env, disp, screen, vis_info, title, x, y, width, height, fscreen); glx_window = glXCreateWindow(disp, configs[0], getCurrentWindow(), NULL); makeCurrent(); - if (ISDEBUGENABLED()) + if (isDebugEnabled()) dumpVisualInfo(disp, vis_info); XFree(configs); XFree(vis_info); @@ -433,7 +433,7 @@ static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title, throwException(env, "Could not find a matching pixel format"); return false; } - if (ISDEBUGENABLED()) + if (isDebugEnabled()) dumpVisualInfo(disp, vis_info); context = glXCreateContext(disp, vis_info, NULL, True); if (context == NULL) { diff --git a/src/native/macosx/hid.cpp b/src/native/macosx/hid.cpp index 56180947..e4794899 100644 --- a/src/native/macosx/hid.cpp +++ b/src/native/macosx/hid.cpp @@ -202,7 +202,7 @@ bool findDevice(hid_device_t *hid_dev, long device_usage_page, long device_usage long usage_page; if (getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsageKey), &usage) && getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsagePageKey), &usage_page)) { - if (ISDEBUGENABLED()) { + if (isDebugEnabled()) { printf("Considering device '"); printProperty(dev_props, CFSTR(kIOHIDProductKey)); printf("', usage page %ld usage %ld\n", usage_page, usage); diff --git a/src/native/macosx/org_lwjgl_Sys.cpp b/src/native/macosx/org_lwjgl_Sys.cpp index f76d3388..8e30e78e 100644 --- a/src/native/macosx/org_lwjgl_Sys.cpp +++ b/src/native/macosx/org_lwjgl_Sys.cpp @@ -88,6 +88,10 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime return hires_timer; } +JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) { + return getVersionString(env); +} + /* * Class: org_lwjgl_Sys * Method: setTime diff --git a/src/native/win32/org_lwjgl_Sys.cpp b/src/native/win32/org_lwjgl_Sys.cpp index c46eaa56..8ce62589 100644 --- a/src/native/win32/org_lwjgl_Sys.cpp +++ b/src/native/win32/org_lwjgl_Sys.cpp @@ -65,6 +65,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jb setDebugEnabled(enabled == JNI_TRUE ? true : false); } +JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) { + return getVersionString(env); +} + /* * Class: org_lwjgl_Sys * Method: getTime