mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
fix particle tick crashing, handle TimeWorker exceptions gracefully
This commit is contained in:
parent
0b0ae3dd44
commit
31c1d1d7da
@ -162,10 +162,13 @@ class ParticleRenderer(
|
||||
translucentMesh = ParticleMesh(renderWindow, translucentMesh.data)
|
||||
|
||||
|
||||
particlesLock.acquire()
|
||||
particlesLock.lock()
|
||||
particleQueueLock.acquire()
|
||||
particles += particleQueue
|
||||
particleQueueLock.release()
|
||||
particlesLock.unlock()
|
||||
|
||||
particlesLock.acquire()
|
||||
|
||||
val time = KUtil.time
|
||||
for (particle in particles) {
|
||||
|
@ -14,7 +14,7 @@ object TimeWorker {
|
||||
while (true) {
|
||||
val currentTime = KUtil.time
|
||||
for (task in TASKS.toSynchronizedSet()) {
|
||||
if (task.getsExecuted) {
|
||||
if (task.executing) {
|
||||
continue
|
||||
}
|
||||
if (currentTime - task.lastExecution <= task.interval) {
|
||||
@ -24,7 +24,7 @@ object TimeWorker {
|
||||
if (!task.lock.tryLock(100L, TimeUnit.MILLISECONDS)) {
|
||||
return@execute
|
||||
}
|
||||
if (task.getsExecuted) {
|
||||
if (task.executing) {
|
||||
task.lock.unlock()
|
||||
return@execute
|
||||
}
|
||||
@ -32,10 +32,14 @@ object TimeWorker {
|
||||
task.lock.unlock()
|
||||
return@execute
|
||||
}
|
||||
task.getsExecuted = true
|
||||
task.runnable.run()
|
||||
task.executing = true
|
||||
try {
|
||||
task.runnable.run()
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
task.lastExecution = currentTime
|
||||
task.getsExecuted = false
|
||||
task.executing = false
|
||||
task.lock.unlock()
|
||||
}
|
||||
if (task.runOnce) {
|
||||
|
@ -22,6 +22,6 @@ data class TimeWorkerTask(
|
||||
val runnable: Runnable,
|
||||
) {
|
||||
val lock = ReentrantLock()
|
||||
var getsExecuted: Boolean = false
|
||||
var executing: Boolean = false
|
||||
var lastExecution: Long = 0L
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user