diff --git a/runtime/src/pipeline_workers.h b/runtime/src/pipeline_workers.h index 7e826512de..48987eb9ca 100644 --- a/runtime/src/pipeline_workers.h +++ b/runtime/src/pipeline_workers.h @@ -67,7 +67,18 @@ class PipelineWorkers { while (batch.next < batch.count) step(batch, lock); batch.done.wait(lock, [&] { return !batch.running; }); lock.unlock(); - if (batch.error) std::rethrow_exception(batch.error); + if (batch.error) { + // Wine 11.0's rethrow_exception throws the stored object itself, not a copy, so the exception_ptr in + // `batch` (a local of this frame) would free it while the throw unwinds, and the caller's handler would + // see no runtime_error. A thread_local reference keeps it alive until this thread's next error. It is + // held through a plain pointer: a thread_local std::exception_ptr has a destructor, which adds a TLS + // callback (__dyn_tls_dtor) to gta6rt (gta6rt_no_tls_callbacks, AGENTS.md). One exception_ptr per + // thread that ever saw an error is never freed. + thread_local std::exception_ptr* in_flight = nullptr; + if (!in_flight) in_flight = new std::exception_ptr; + *in_flight = std::move(batch.error); + std::rethrow_exception(*in_flight); + } } // Ends the workers once each has finished the job it is in. A run() in progress on another thread finishes its