From d721d0fb30b6a78bfe8dd9abc2e1480b435f3c20 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 8 May 2024 21:08:40 +0200 Subject: [PATCH] :art: better vm_force_run --- src/emit/comptime.c | 4 ++-- src/vm/vm.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/emit/comptime.c b/src/emit/comptime.c index 0206a952..ce0054b5 100644 --- a/src/emit/comptime.c +++ b/src/emit/comptime.c @@ -24,7 +24,7 @@ ANN2(1) void comptime_end(const Emitter emit, const size_t size, void *data) { const VM_Shred shred = new_vm_shred(emit->gwion->mp, code); vm_add_shred(vm, shred); const bool loop = vm->shreduler->loop; - vm_run(vm); - vm->bbq->is_running = true; + vm->shreduler->loop = false; + vm_force_run(vm); vm->shreduler->loop = loop; } diff --git a/src/vm/vm.c b/src/vm/vm.c index 624241ba..5613b511 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -1657,8 +1657,15 @@ ANN void vm_run_audio(const VM *vm) { void vm_force_run(const VM *vm) { const bool is_running = vm->shreduler->bbq->is_running; + struct ShredTick_ *curr = vm->shreduler->curr; + VM_Shred shred = (VM_Shred) vector_back(&vm->shreduler->active_shreds); + vm->shreduler->curr = shred->tick; + const m_uint pos = vm->shreduler->bbq->pos; + vm->shreduler->bbq->pos = 0; vm_run(vm); + vm->shreduler->curr = curr; vm->shreduler->bbq->is_running = is_running; + vm->shreduler->bbq->pos = pos; } VM *new_vm(MemPool p, const bool audio) { -- 2.43.0