diff options
author | bunnei <bunneidev@gmail.com> | 2022-03-08 12:36:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-08 12:36:57 -0800 |
commit | f2743b41b0f8f82bcfe678cf735819ea987b62b4 (patch) | |
tree | f5cd00237eda3d4ea49a434e8f01f2a912ded9ce /src | |
parent | 35309f27ed129dfda8b6ba7f126bf22f12bb9b4c (diff) | |
parent | b5e60ae1b0568d6c9e47134dd2bda70906a2dad9 (diff) |
Merge pull request #7986 from lat9nq/vk-callback
core, video_core: Fix two crashes when failing to create the emulated GPU instance
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core.cpp | 4 | ||||
-rw-r--r-- | src/core/frontend/emu_window.h | 11 | ||||
-rw-r--r-- | src/video_core/video_core.cpp | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index b0cfee3ee0..c60a784c3e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -326,7 +326,9 @@ struct System::Impl { is_powered_on = false; exit_lock = false; - gpu_core->NotifyShutdown(); + if (gpu_core != nullptr) { + gpu_core->NotifyShutdown(); + } services.reset(); service_manager.reset(); diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index e413a520ab..b3bffecb22 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 diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 329bf4defd..2f25945858 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -50,6 +50,7 @@ std::unique_ptr<Tegra::GPU> CreateGPU(Core::Frontend::EmuWindow& emu_window, Cor gpu->BindRenderer(std::move(renderer)); return gpu; } catch (const std::runtime_error& exception) { + scope.Cancel(); LOG_ERROR(HW_GPU, "Failed to initialize GPU: {}", exception.what()); return nullptr; } |