Fix LWJGL initialization error handling
This commit is contained in:
parent
25a944baf4
commit
2cf769b599
1 changed files with 37 additions and 32 deletions
|
@ -102,13 +102,7 @@ public final class GlfwSubsystem extends ApiClass {
|
||||||
*
|
*
|
||||||
* @since v1-alpha2
|
* @since v1-alpha2
|
||||||
*/
|
*/
|
||||||
private final GLFWErrorCallback errorCallback = GLFWErrorCallback.create(new GLFWErrorCallbackI() {
|
private GLFWErrorCallback errorCallback = null;
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void invoke(int error, long description) {
|
|
||||||
new WindowingErrorEvent().callEvent(description + " (" + error + ")");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this subsystem.
|
* Initializes this subsystem.
|
||||||
|
@ -137,33 +131,44 @@ public final class GlfwSubsystem extends ApiClass {
|
||||||
@Override
|
@Override
|
||||||
public void initializeApi() {
|
public void initializeApi() {
|
||||||
logger.verb("Initializing GLFW");
|
logger.verb("Initializing GLFW");
|
||||||
|
try {
|
||||||
|
if (!Miscellaneous.onMainThread()) {
|
||||||
|
logger.crash("Unable to initialize GLFW on a non-main thread", new NotOnMainThreadException(), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Miscellaneous.onMainThread()) {
|
// Set error callback
|
||||||
logger.crash("Unable to initialize GLFW on a non-main thread", new NotOnMainThreadException(), true);
|
errorCallback = GLFWErrorCallback.create(new GLFWErrorCallbackI() {
|
||||||
return;
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void invoke(int error, long description) {
|
||||||
|
new WindowingErrorEvent().callEvent(description + " (" + error + ")");
|
||||||
|
}
|
||||||
|
}).set();
|
||||||
|
|
||||||
|
// Set init hints
|
||||||
|
switch (GlfwSubsystemConfiguration.getInstance().getPlatform()) {
|
||||||
|
case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
|
||||||
|
case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
|
||||||
|
case X11 -> tryPlatform(GLFW_PLATFORM_X11);
|
||||||
|
case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
|
||||||
|
case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
|
||||||
|
case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
|
||||||
|
}
|
||||||
|
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GlfwSubsystemConfiguration.getInstance().isDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
|
||||||
|
|
||||||
|
// Initialize GLFW
|
||||||
|
if (!glfwInit())
|
||||||
|
logger.crash("Failed to initialize GLFW");
|
||||||
|
|
||||||
|
// Initialize classes
|
||||||
|
internalApi = new GlfwInternalClass();
|
||||||
|
management = new GlfwManagementClass();
|
||||||
|
} catch (UnsatisfiedLinkError error) {
|
||||||
|
logger.crash("Failed to load LWJGL native libraries", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set error callback
|
|
||||||
errorCallback.set();
|
|
||||||
|
|
||||||
// Set init hints
|
|
||||||
switch (GlfwSubsystemConfiguration.getInstance().getPlatform()) {
|
|
||||||
case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
|
|
||||||
case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
|
|
||||||
case X11 -> tryPlatform(GLFW_PLATFORM_X11);
|
|
||||||
case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
|
|
||||||
case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
|
|
||||||
case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
|
|
||||||
}
|
|
||||||
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GlfwSubsystemConfiguration.getInstance().isDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
|
|
||||||
|
|
||||||
// Initialize GLFW
|
|
||||||
if (!glfwInit())
|
|
||||||
logger.crash("Failed to initialize GLFW");
|
|
||||||
|
|
||||||
// Initialize classes
|
|
||||||
internalApi = new GlfwInternalClass();
|
|
||||||
management = new GlfwManagementClass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
Loading…
Reference in a new issue