diff --git a/client/application.cpp b/client/application.cpp index 8718fe4a..2cf07eed 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -881,15 +881,16 @@ void application::set_wifi_locks(bool enabled) void application::cleanup() { + // Remove all scenes before destroying the allocator + scene_stack.clear(); + if (allocator) { - // vmaDestroyAllocator(allocator); - // allocator = nullptr; + vmaDestroyAllocator(allocator); + allocator = nullptr; } #ifdef __ANDROID__ - - jni::jni_thread::detach(); #endif } @@ -918,10 +919,10 @@ void application::loop() auto scene = current_scene(); if (scene) { - if (scene != last_scene) + if (auto tmp = last_scene.lock(); scene != tmp) { - if (last_scene) - last_scene->on_unfocused(); + if (tmp) + tmp->on_unfocused(); scene->on_focused(); diff --git a/client/application.h b/client/application.h index 5ac22694..1ed47e21 100644 --- a/client/application.h +++ b/client/application.h @@ -125,7 +125,7 @@ class application : public singleton std::mutex scene_stack_lock; std::vector> scene_stack; - std::shared_ptr last_scene; + std::weak_ptr last_scene; void loop(); diff --git a/client/render/scene_renderer.cpp b/client/render/scene_renderer.cpp index 893868be..8045fe9b 100644 --- a/client/render/scene_renderer.cpp +++ b/client/render/scene_renderer.cpp @@ -216,13 +216,19 @@ scene_renderer::scene_renderer(vk::raii::Device & device, vk::raii::PhysicalDevi scene_renderer::~scene_renderer() { - std::vector fences; - for (auto & i: frame_resources) - fences.push_back(*i.fence); + wait_idle(); +} + +void scene_renderer::wait_idle() +{ + std::vector fences(frame_resources.size()); + for(auto&& [i, f]: utils::enumerate(frame_resources)) + fences[i] = *f.fence; device.waitForFences(fences, true, 1'000'000'000); // TODO check for timeout } + vk::raii::RenderPass scene_renderer::create_renderpass() { vk::RenderPassCreateInfo info; diff --git a/client/render/scene_renderer.h b/client/render/scene_renderer.h index 31d5327f..b21c48bb 100644 --- a/client/render/scene_renderer.h +++ b/client/render/scene_renderer.h @@ -148,10 +148,10 @@ public: vk::raii::CommandBuffer cb = nullptr; std::vector> resources; - // Uniform buffer for per-view and per-instance data // host visible, host coherent buffer_allocation staging_buffer; + // device local // buffer_allocation uniform_buffer; }; @@ -181,4 +181,6 @@ public: { return default_material; } + + void wait_idle(); }; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index cbe6ec52..7619b945 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -38,7 +38,11 @@ static const std::string discover_service = "_wivrn._tcp.local."; -scenes::lobby::~lobby() {} +scenes::lobby::~lobby() +{ + if (renderer) + renderer->wait_idle(); +} static std::string choose_webxr_profile() {