Implemented version check to check for incompatible native libraries

This commit is contained in:
Elias Naur 2004-03-27 14:09:55 +00:00
parent b98677fb47
commit 021e03eea5
10 changed files with 61 additions and 20 deletions

View file

@ -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);

View file

@ -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"); \

View file

@ -40,7 +40,16 @@
#include <stdlib.h>
#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);
}

View file

@ -43,11 +43,8 @@
#include <jni.h>
#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);

View file

@ -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

View file

@ -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

View file

@ -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) {

View file

@ -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);

View file

@ -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

View file

@ -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