mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
eros: don't use WeakReferenceQueue, use stage list
This should fix an unknown crash on macos
This commit is contained in:
parent
078dbdc800
commit
97bfe87f0a
@ -13,7 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.eros.util
|
||||
|
||||
import com.sun.javafx.util.WeakReferenceQueue
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||
@ -46,7 +45,7 @@ import kotlin.reflect.jvm.javaField
|
||||
|
||||
object JavaFXUtil {
|
||||
private const val DEFAULT_STYLE = "resource:minosoft:eros/style.css"
|
||||
private val stages: WeakReferenceQueue<Stage> = WeakReferenceQueue()
|
||||
private val stages = StageList()
|
||||
lateinit var JAVA_FX_THREAD: Thread
|
||||
lateinit var MINOSOFT_LOGO: Image
|
||||
lateinit var HOST_SERVICES: HostServices
|
||||
@ -62,8 +61,8 @@ object JavaFXUtil {
|
||||
|
||||
ErosProfileManager.selected.theme::theme.observeFX(this) {
|
||||
stages.cleanup()
|
||||
for (stage in stages.iterator().unsafeCast<Iterator<Stage?>>()) {
|
||||
stage ?: continue
|
||||
for (stage in stages.iterator()) {
|
||||
stage ?: break
|
||||
stage.scene.stylesheets.clear()
|
||||
stage.scene.stylesheets.add(DEFAULT_STYLE)
|
||||
stage.scene.stylesheets.add(getThemeURL(it))
|
||||
|
68
src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt
Normal file
68
src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.eros.util
|
||||
|
||||
import de.bixilon.kutil.concurrent.lock.simple.SimpleLock
|
||||
import javafx.stage.Stage
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class StageList : Iterable<Stage?> {
|
||||
private val stages: MutableList<WeakReference<Stage>> = mutableListOf()
|
||||
val lock = SimpleLock()
|
||||
|
||||
private fun <T> MutableList<WeakReference<T>>.cleanup() {
|
||||
val iterator = this.iterator()
|
||||
for (reference in iterator) {
|
||||
if (reference.get() != null) {
|
||||
continue
|
||||
}
|
||||
iterator.remove()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun cleanup() {
|
||||
lock.lock()
|
||||
stages.cleanup()
|
||||
lock.unlock()
|
||||
}
|
||||
|
||||
fun add(stage: Stage) {
|
||||
lock.lock()
|
||||
stages += WeakReference(stage)
|
||||
lock.unlock()
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<Stage?> {
|
||||
return object : Iterator<Stage?> {
|
||||
private val iterator = stages.iterator()
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return iterator.hasNext()
|
||||
}
|
||||
|
||||
override fun next(): Stage? {
|
||||
while (iterator.hasNext()) {
|
||||
val entry = iterator.next().get()
|
||||
if (entry != null) {
|
||||
return entry
|
||||
}
|
||||
iterator.remove()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user