Skip to content

Commit bb5390a

Browse files
authored
Standalone: Add and use GLFWException for standalone use
GitHub: #124
1 parent 8ac267c commit bb5390a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
package gg.essential.universal.standalone.glfw
3+
4+
@Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
5+
class GLFWException(
6+
val errorMessage: String,
7+
val glfwErrorMessage: String?,
8+
val glfwErrorCode: Int?,
9+
) : RuntimeException("$errorMessage: $glfwErrorMessage${if (glfwErrorCode != null) " (code $glfwErrorCode)" else ""}")

standalone/src/main/kotlin/gg/essential/universal/standalone/glfw/GlfwWindow.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ class GlfwWindow(
6464
?.let { return@run it }
6565

6666
// Failed to create any context, fetch the error and throw
67-
val message = MemoryStack.stackPush().use { stack ->
67+
val (message, code) = MemoryStack.stackPush().use { stack ->
6868
val pointer = stack.mallocPointer(1)
6969
val error = GLFW.glfwGetError(pointer)
7070
if (error != GLFW.GLFW_NO_ERROR) {
71-
"${MemoryUtil.memUTF8Safe(pointer.get(0))} (code $error)"
71+
MemoryUtil.memUTF8Safe(pointer.get(0)) to error
7272
} else {
73-
"unknown error"
73+
"unknown error" to null
7474
}
7575
}
76-
throw RuntimeException("Failed to create the GLFW window: $message")
76+
throw GLFWException("Failed to create the GLFW window", message, code)
7777
}
7878

7979
init {
@@ -130,4 +130,4 @@ class GlfwWindow(
130130
override fun close() {
131131
GLFW.glfwDestroyWindow(glfwId)
132132
}
133-
}
133+
}

0 commit comments

Comments
 (0)