Fix having multiple starbound clients being broken
This commit is contained in:
parent
3ad0e78c10
commit
328cab8127
@ -104,7 +104,7 @@ class StarboundClient : Closeable {
|
|||||||
|
|
||||||
var fullbright = true
|
var fullbright = true
|
||||||
|
|
||||||
var gameTerminated = false
|
var clientTerminated = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,6 +156,8 @@ class StarboundClient : Closeable {
|
|||||||
lock.lock()
|
lock.lock()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
clients++
|
||||||
|
|
||||||
if (!glfwInitialized) {
|
if (!glfwInitialized) {
|
||||||
check(GLFW.glfwInit()) { "Unable to initialize GLFW" }
|
check(GLFW.glfwInit()) { "Unable to initialize GLFW" }
|
||||||
glfwInitialized = true
|
glfwInitialized = true
|
||||||
@ -991,21 +993,30 @@ class StarboundClient : Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
if (gameTerminated)
|
if (clientTerminated)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (window != MemoryUtil.NULL) {
|
lock.lock()
|
||||||
Callbacks.glfwFreeCallbacks(window)
|
|
||||||
GLFW.glfwDestroyWindow(window)
|
|
||||||
}
|
|
||||||
|
|
||||||
GLFW.glfwTerminate()
|
try {
|
||||||
GLFW.glfwSetErrorCallback(null)?.free()
|
if (window != MemoryUtil.NULL) {
|
||||||
|
Callbacks.glfwFreeCallbacks(window)
|
||||||
|
GLFW.glfwDestroyWindow(window)
|
||||||
|
}
|
||||||
|
|
||||||
gameTerminated = true
|
if (--clients == 0) {
|
||||||
|
GLFW.glfwTerminate()
|
||||||
|
GLFW.glfwSetErrorCallback(null)?.free()
|
||||||
|
glfwInitialized = false
|
||||||
|
}
|
||||||
|
|
||||||
for (callback in terminateCallbacks) {
|
clientTerminated = true
|
||||||
callback.invoke()
|
|
||||||
|
for (callback in terminateCallbacks) {
|
||||||
|
callback.invoke()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
lock.unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1021,6 +1032,8 @@ class StarboundClient : Closeable {
|
|||||||
private val lock = ReentrantLock()
|
private val lock = ReentrantLock()
|
||||||
@Volatile
|
@Volatile
|
||||||
private var glfwInitialized = false
|
private var glfwInitialized = false
|
||||||
|
@Volatile
|
||||||
|
private var clients = 0
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun readInternal(file: String): String {
|
fun readInternal(file: String): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user