Fix LWJGL initialization error handling

This commit is contained in:
JeremyStar™ 2024-10-15 04:06:52 +02:00
parent 25a944baf4
commit 2cf769b599
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -102,13 +102,7 @@ public final class GlfwSubsystem extends ApiClass {
*
* @since v1-alpha2
*/
private final GLFWErrorCallback errorCallback = GLFWErrorCallback.create(new GLFWErrorCallbackI() {
/** {@inheritDoc} */
@Override
public void invoke(int error, long description) {
new WindowingErrorEvent().callEvent(description + " (" + error + ")");
}
});
private GLFWErrorCallback errorCallback = null;
/**
* Initializes this subsystem.
@ -137,14 +131,22 @@ public final class GlfwSubsystem extends ApiClass {
@Override
public void initializeApi() {
logger.verb("Initializing GLFW");
try {
if (!Miscellaneous.onMainThread()) {
logger.crash("Unable to initialize GLFW on a non-main thread", new NotOnMainThreadException(), true);
return;
}
// Set error callback
errorCallback.set();
errorCallback = GLFWErrorCallback.create(new GLFWErrorCallbackI() {
/**
* {@inheritDoc}
*/
@Override
public void invoke(int error, long description) {
new WindowingErrorEvent().callEvent(description + " (" + error + ")");
}
}).set();
// Set init hints
switch (GlfwSubsystemConfiguration.getInstance().getPlatform()) {
@ -164,6 +166,9 @@ public final class GlfwSubsystem extends ApiClass {
// Initialize classes
internalApi = new GlfwInternalClass();
management = new GlfwManagementClass();
} catch (UnsatisfiedLinkError error) {
logger.crash("Failed to load LWJGL native libraries", error);
}
}
/** {@inheritDoc} */