mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-13 22:46:06 +09:00
exception on the vm should exit the app
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||
import net.torvald.tsvm.peripheral.ReferenceGraphicsAdapter2
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2022-12-15.
|
||||
@@ -21,7 +21,7 @@ object VMSetupBroker {
|
||||
* @param vmRunners Hashmap on the host of VMs that holds the instances of the VMRunners for the given VM. Key: Int(VM's identifier), value: [net.torvald.tsvm.VMRunner]
|
||||
* @param coroutineJobs Hashmap on the host of VMs that holds the coroutine-job object for the currently running VM-instance. Key: Int(VM's identifier), value: [kotlinx.coroutines.Job]
|
||||
*/
|
||||
fun initVMenv(vm: VM, gpu: GraphicsAdapter, vmRunners: HashMap<Int, VMRunner>, coroutineJobs: HashMap<Int, Job>) {
|
||||
fun initVMenv(vm: VM, gpu: GraphicsAdapter, vmRunners: HashMap<Int, VMRunner>, coroutineJobs: HashMap<Int, Job>, whatToDoOnVmException: (Throwable) -> Unit) {
|
||||
vm.init()
|
||||
|
||||
try {
|
||||
@@ -37,7 +37,14 @@ object VMSetupBroker {
|
||||
vm.poke(-90L, 0)
|
||||
|
||||
vmRunners[vm.id] = VMRunnerFactory(vm.assetsDir, vm, "js")
|
||||
coroutineJobs[vm.id] = GlobalScope.launch { vmRunners[vm.id]?.executeCommand(vm.roms[0]!!.readAll()) }
|
||||
coroutineJobs[vm.id] = GlobalScope.launch {
|
||||
try {
|
||||
vmRunners[vm.id]?.executeCommand(vm.roms[0]!!.readAll())
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
whatToDoOnVmException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.torvald.tsvm.peripheral
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.audio.AudioDevice
|
||||
import com.badlogic.gdx.backends.lwjgl3.audio.OpenALLwjgl3Audio
|
||||
import com.badlogic.gdx.utils.Queue
|
||||
import net.torvald.UnsafeHelper
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
|
||||
import net.torvald.tsvm.ThreeFiveMiniUfloat
|
||||
import net.torvald.tsvm.VM
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
private fun Boolean.toInt() = if (this) 1 else 0
|
||||
|
||||
@@ -36,6 +36,11 @@ class AudioAdapter(val vm: VM) : PeriBase {
|
||||
private val renderThreads = Array(4) { Thread(getRenderFun(it)) }
|
||||
private val writeQueueingThreads = Array(4) { Thread(getQueueingFun(it)) }
|
||||
|
||||
private val threadExceptionHandler = Thread.UncaughtExceptionHandler { thread, throwable ->
|
||||
throwable.printStackTrace()
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
private fun getRenderFun(pheadNum: Int): () -> Unit = { while (true) {
|
||||
render(playheads[pheadNum])
|
||||
Thread.sleep(1)
|
||||
@@ -91,8 +96,8 @@ class AudioAdapter(val vm: VM) : PeriBase {
|
||||
|
||||
|
||||
// printdbg("AudioAdapter latency: ${audioDevice.latency}")
|
||||
renderThreads.forEach { it.start() }
|
||||
writeQueueingThreads.forEach { it.start() }
|
||||
renderThreads.forEach { it.uncaughtExceptionHandler = threadExceptionHandler; it.start() }
|
||||
writeQueueingThreads.forEach { it.uncaughtExceptionHandler = threadExceptionHandler; it.start() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user