1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-28 01:20:55 +01:00

WebGPU: release image bind groups in ImGui_ImplWGPU_NewFrame

We can't store the bind groups during all the execution because user could
release the texture.
This commit is contained in:
Gatgat 2024-10-08 14:23:39 +02:00
parent 520a164fcc
commit ac2c012358

View File

@ -190,6 +190,15 @@ static void SafeRelease(WGPUBindGroup& res)
wgpuBindGroupRelease(res);
res = nullptr;
}
template <typename T>
static void SafeRelease(ImGuiStorage& bind_groups_storage)
{
for (int i = 0; i < bind_groups_storage.Data.size(); i++)
{
SafeRelease((T&)bind_groups_storage.Data[i].val_p);
}
bind_groups_storage.Clear();
}
static void SafeRelease(WGPUBuffer& res)
{
if (res)
@ -816,6 +825,12 @@ void ImGui_ImplWGPU_NewFrame()
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
if (!bd->pipelineState)
ImGui_ImplWGPU_CreateDeviceObjects();
// The user could have deallocated a stored texture, and
// potentially allocated a new one that has the same id as
// a previously registered one.
// To mitigate this, we release the registered bind groups.
SafeRelease<WGPUBindGroup>(bd->renderResources.ImageBindGroups);
}
//-----------------------------------------------------------------------------