Fix destruction order to avoid memory leaks reported by VMA
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class application : public singleton<application>
|
||||
|
||||
std::mutex scene_stack_lock;
|
||||
std::vector<std::shared_ptr<scene>> scene_stack;
|
||||
std::shared_ptr<scene> last_scene;
|
||||
std::weak_ptr<scene> last_scene;
|
||||
|
||||
void loop();
|
||||
|
||||
|
||||
@@ -216,13 +216,19 @@ scene_renderer::scene_renderer(vk::raii::Device & device, vk::raii::PhysicalDevi
|
||||
|
||||
scene_renderer::~scene_renderer()
|
||||
{
|
||||
std::vector<vk::Fence> fences;
|
||||
for (auto & i: frame_resources)
|
||||
fences.push_back(*i.fence);
|
||||
wait_idle();
|
||||
}
|
||||
|
||||
void scene_renderer::wait_idle()
|
||||
{
|
||||
std::vector<vk::Fence> 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;
|
||||
|
||||
@@ -148,10 +148,10 @@ public:
|
||||
vk::raii::CommandBuffer cb = nullptr;
|
||||
std::vector<std::shared_ptr<void>> 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();
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user