From 1f24a4e520004d48799a27b159432aa0b8634628 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 7 Mar 2022 03:35:34 -0500 Subject: emu_window: Create a way to Cancel the exit of a Scoped If a GraphicsContext is destroyed before its Scoped is destroyed, this causes a crash as the Scoped tries to call a method in the destroyed context on exit. Add a way to Cancel the call when we know that calling the GraphicsContext will not work. --- src/core/frontend/emu_window.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core/frontend/emu_window.h') diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index e413a520a..b3bffecb2 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h @@ -42,11 +42,20 @@ public: context.MakeCurrent(); } ~Scoped() { - context.DoneCurrent(); + if (active) { + context.DoneCurrent(); + } + } + + /// In the event that context was destroyed before the Scoped is destroyed, this provides a + /// mechanism to prevent calling a destroyed object's method during the deconstructor + void Cancel() { + active = false; } private: GraphicsContext& context; + bool active{true}; }; /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value -- cgit v1.2.3