diff --git a/src/common/rendering/vulkan/textures/vk_texture.cpp b/src/common/rendering/vulkan/textures/vk_texture.cpp index c5f642119..0b86ae101 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.cpp +++ b/src/common/rendering/vulkan/textures/vk_texture.cpp @@ -397,6 +397,13 @@ void VkTextureManager::CreatePrefiltermap(int size, int count, TArray& void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCount, TArray&& newPixelData) { + if (newLMTextureCount == 0) // If there is no lightmap we create a dummy texture to simplify code elsewhere + { + newLMTextureSize = 1; + newLMTextureCount = 1; + newPixelData = {}; + } + if (Lightmap.Size == newLMTextureSize && Lightmap.Count == newLMTextureCount + 1 && newPixelData.Size() == 0) return; diff --git a/src/common/rendering/vulkan/vk_lightmapper.cpp b/src/common/rendering/vulkan/vk_lightmapper.cpp index 88c8c65ac..163869a32 100644 --- a/src/common/rendering/vulkan/vk_lightmapper.cpp +++ b/src/common/rendering/vulkan/vk_lightmapper.cpp @@ -73,7 +73,8 @@ void VkLightmapper::ReleaseResources() void VkLightmapper::SetLevelMesh(LevelMesh* level) { mesh = level; - UpdateAccelStructDescriptors(); + if (mesh) + UpdateAccelStructDescriptors(); lightmapRaytraceLast.Reset(); lastPixelCount = 0; diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index 3454c2a4e..fc7e3f700 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -521,12 +521,9 @@ void VulkanRenderDevice::BeginFrame() { levelMeshChanged = false; mLevelMesh->SetLevelMesh(levelMesh); - - if (levelMesh && levelMesh->Lightmap.TextureCount > 0) - { + if (levelMesh) GetTextureManager()->CreateLightmap(levelMesh->Lightmap.TextureSize, levelMesh->Lightmap.TextureCount, std::move(levelMesh->Lightmap.TextureData)); - GetLightmapper()->SetLevelMesh(levelMesh); - } + GetLightmapper()->SetLevelMesh(levelMesh); } SetViewportRects(nullptr); diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 945e3609d..275764767 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -379,6 +379,8 @@ void FLevelLocals::ClearLevelData(bool fullgc) if (levelMesh) delete levelMesh; aabbTree = nullptr; levelMesh = nullptr; + if (screen) + screen->SetLevelMesh(nullptr); if (screen && screen->mShadowMap) screen->mShadowMap->SetAABBTree(nullptr); } diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index ebddf1f1c..db1941d13 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -238,6 +238,10 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals& doomMap) r_viewpoint.camera = oldcamera; } +DoomLevelMesh::~DoomLevelMesh() +{ +} + void DoomLevelMesh::SetLimits(FLevelLocals& doomMap) { // Try to estimate what the worst case memory needs are for the level diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index d81dae882..f569e27a2 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -90,6 +90,7 @@ class DoomLevelMesh : public LevelMesh, public UpdateLevelMesh { public: DoomLevelMesh(FLevelLocals &doomMap); + ~DoomLevelMesh(); void PrintSurfaceInfo(const LevelMeshSurface* surface);