diff --git a/src/Viewer/VRManager.cxx b/src/Viewer/VRManager.cxx index fa768f51a..6fc921698 100644 --- a/src/Viewer/VRManager.cxx +++ b/src/Viewer/VRManager.cxx @@ -29,6 +29,11 @@ namespace flightgear { +// Unfortunately, this can't be scoped inside VRManager::instance(). +// If its initialisation completes after main() calls atexit(fgExitCleanup), +// then its destruction should take place before fgExitCleanup() is called. +static osg::ref_ptr managerInstance; + VRManager::VRManager() : _reloadCompositorCallback(new ReloadCompositorCallback(this)), _propXrLayersValidation("/sim/vr/openxr/layers/validation"), @@ -88,8 +93,12 @@ VRManager::VRManager() : VRManager *VRManager::instance() { - static osg::ref_ptr single = new VRManager; - return single; + static bool initialised = false; + if (!initialised) { + managerInstance = new VRManager; + initialised = true; + } + return managerInstance; } void VRManager::syncProperties()