Own Windows app lifetime in runtime shell

This commit is contained in:
2026-06-17 09:46:43 +02:00
parent 10a3c0498e
commit 25eff166f6
6 changed files with 73 additions and 31 deletions

View File

@@ -18,6 +18,7 @@ namespace pp::platform::windows {
namespace {
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
App* app = nullptr;
AppRuntime* runtime = nullptr;
WacomTablet* tablet = nullptr;
@@ -132,6 +133,14 @@ App* bound_app() noexcept
return retained_runtime_state().app;
}
void release_bound_app() noexcept
{
auto& state = retained_runtime_state();
bind_runtime(nullptr);
bind_app(nullptr);
state.owned_app.reset();
}
void bind_runtime(AppRuntime* runtime) noexcept
{
retained_runtime_state().runtime = runtime;
@@ -177,7 +186,9 @@ int run_main_application(int argc, char** argv)
auto& state = retained_state();
state.hInst = GetModuleHandle(NULL);
auto* app = new App();
auto& runtime_state = retained_runtime_state();
runtime_state.owned_app = std::make_unique<App>();
auto* app = runtime_state.owned_app.get();
bind_app(app);
bind_runtime(&app->runtime());
bind_wacom_tablet(&WacomTablet::I);
@@ -209,13 +220,11 @@ int run_main_application(int argc, char** argv)
case pp::platform::windows::MainStartupResult::Ok:
break;
case pp::platform::windows::MainStartupResult::GladLoadFailure:
bind_app(nullptr);
bind_runtime(nullptr);
release_bound_app();
bind_wacom_tablet(nullptr);
return 0;
case pp::platform::windows::MainStartupResult::MissingCoreContextSupport:
bind_app(nullptr);
bind_runtime(nullptr);
release_bound_app();
bind_wacom_tablet(nullptr);
return -1;
}
@@ -230,8 +239,7 @@ int run_main_application(int argc, char** argv)
case const_hash("convert"):
app->initShaders();
app->cmd_convert(argv[2], argv[3]);
bind_app(nullptr);
bind_runtime(nullptr);
release_bound_app();
bind_wacom_tablet(nullptr);
return 0;
case const_hash("-vrmode"):
@@ -243,6 +251,7 @@ int run_main_application(int argc, char** argv)
}
pp::platform::windows::run_main_window_runtime(startup, start_in_vr, splash);
release_bound_app();
bind_wacom_tablet(nullptr);
return 0;
}