]> git.tdb.fi Git - libs/game.git/commitdiff
Adjust destruction order of Application members
authorMikko Rasa <tdb@tdb.fi>
Tue, 22 Apr 2025 21:38:09 +0000 (00:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 22 Apr 2025 21:44:48 +0000 (00:44 +0300)
The VR system needs to be destroyed before the GL device because it
holds some Vulkan images created using the latter.

source/gameview/application.h

index 2ac7570695ae8d462e6a0da9c666c0bb4683b154..9eeac84ed7da9d44d6f6c0e28e06f1825d5f0cca 100644 (file)
@@ -28,9 +28,10 @@ public:
 protected:
        Graphics::Display display;
        Graphics::Window window;
-       std::unique_ptr<VR::System> vr_system;
+       std::unique_ptr<VR::System> vr_init;
        GL::Device gl_device;
        ResourcesType resources;
+       std::unique_ptr<VR::System> vr_system;
        Game::Director director;
        GL::WindowView gl_view;
        Presenter presenter;
@@ -40,7 +41,7 @@ public:
        Application(Features = NO_FEATURES);
 
 protected:
-       GL::DeviceOptions create_gl_device_options();
+       static GL::DeviceOptions create_gl_device_options(VR::System * = nullptr);
 
        int main() override;
 protected:
@@ -50,8 +51,9 @@ protected:
 template<typename T, typename R>
 Application<T, R>::Application(Features features):
        window(display, 1920, 1080),
-       vr_system(features==VIRTUAL_REALITY ? VR::System::create_autodetect() : nullptr),
-       gl_device(window, create_gl_device_options()),
+       vr_init(features==VIRTUAL_REALITY ? VR::System::create_autodetect() : nullptr),
+       gl_device(window, create_gl_device_options(vr_init.get())),
+       vr_system(move(vr_init)),
        director(resources),
        gl_view(window),
        presenter(director, gl_view),
@@ -68,11 +70,11 @@ Application<T, R>::Application(Features features):
 }
 
 template<typename T, typename R>
-GL::DeviceOptions Application<T, R>::create_gl_device_options()
+GL::DeviceOptions Application<T, R>::create_gl_device_options(VR::System *vr_sys)
 {
        GL::DeviceOptions opts = GL::Device::create_default_options();
-       if(vr_system)
-               vr_system->fill_gl_device_options(opts);
+       if(vr_sys)
+               vr_sys->fill_gl_device_options(opts);
        return opts;
 }