correctly destroy stuff

This commit is contained in:
Till Wübbers
2025-04-29 09:52:19 +02:00
parent 91e9566747
commit 234a9b1732
4 changed files with 42 additions and 18 deletions

View File

@@ -58,7 +58,7 @@ namespace Game
SetInstance(instance);
ResetScratch();
Puzzle::LoadStaticPuzzleData();
SetupInstance.Rendering.Setup({false});
SetupInstance.Rendering.Setup({});
instance.GameLevel.Setup(shared.Game);
instance.IsInitialized = true;
}

View File

@@ -84,21 +84,7 @@ void DitherGen(DitherData& data, int32_t recursion)
}
// Upload textures
if (isValid(data.PreviewTex))
{
bgfx::destroy(data.PreviewTex);
data.PreviewTex = BGFX_INVALID_HANDLE;
}
if (isValid(data.FinalTex))
{
bgfx::destroy(data.FinalTex);
data.FinalTex = BGFX_INVALID_HANDLE;
}
if (isValid(data.RampTex))
{
bgfx::destroy(data.RampTex);
data.RampTex = BGFX_INVALID_HANDLE;
}
CleanupDitherData(data);
const bgfx::Memory* memPreview = bgfx::makeRef(data.DitherTex, texPixelCount * sizeof(Vec4));
const bgfx::Memory* memFinal = bgfx::makeRef(data.DitherTex, texPixelCount * sizeof(Vec4));
const bgfx::Memory* memRamp = bgfx::makeRef(data.BrightnessRamp, sizeof(data.BrightnessRamp));
@@ -123,3 +109,22 @@ void DitherGen(DitherData& data, int32_t recursion)
data.RampSampler = bgfx::createUniform("s_rampSampler", bgfx::UniformType::Sampler);
}
}
void CleanupDitherData(DitherData& data)
{
if (isValid(data.PreviewTex))
{
bgfx::destroy(data.PreviewTex);
data.PreviewTex = BGFX_INVALID_HANDLE;
}
if (isValid(data.FinalTex))
{
bgfx::destroy(data.FinalTex);
data.FinalTex = BGFX_INVALID_HANDLE;
}
if (isValid(data.RampTex))
{
bgfx::destroy(data.RampTex);
data.RampTex = BGFX_INVALID_HANDLE;
}
}

View File

@@ -24,3 +24,4 @@ struct DitherData
};
void DitherGen(DitherData& data, int32_t recursion);
void CleanupDitherData(DitherData& data);

View File

@@ -6,6 +6,7 @@
#include "../Tools.h"
#include "Rendering.h"
#include "Dither.h"
#include "SDL3/SDL_events.h" // IWYU pragma: keep
#include "backends/imgui_impl_sdl3.h"
#include "bgfx/defines.h"
@@ -326,9 +327,10 @@ namespace Game
bgfx::Init init;
init.type = bgfx::RendererType::Direct3D12;
#ifdef _DEBUG
// init.debug = true;
#else
init.debug = true;
// init.debug = false;
#else
init.debug = false;
#endif
init.platformData.nwh = shared.Window.Handle;
init.platformData.ndt = nullptr;
@@ -558,6 +560,22 @@ namespace Game
ZoneScopedN("Shutdown");
LOG("--- RENDERING_SHUTDOWN ---");
for (int32_t i = 0; i < BX_COUNTOF(Textures); ++i)
{
if (isValid(Textures[i].RenderHandle))
{
bgfx::destroy(Textures[i].RenderHandle);
Textures[i].RenderHandle = {bgfx::kInvalidHandle};
}
}
for (int32_t i = 0; i < ModelCount; ++i)
{
bgfx::destroy(Models[i].VertexBuffer);
bgfx::destroy(Models[i].IndexBuffer);
}
ModelCount = 0;
CleanupDitherData(DitherTextures);
if (SetupData.UseImgui)
{
ImGui::SaveIniSettingsToDisk("imgui.ini");