Fix crash when switching from a level with lightmaps to one without

This commit is contained in:
Magnus Norddahl 2025-01-19 12:36:40 +01:00
commit d435c9c144
6 changed files with 18 additions and 6 deletions

View file

@ -397,6 +397,13 @@ void VkTextureManager::CreatePrefiltermap(int size, int count, TArray<uint16_t>&
void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCount, TArray<uint16_t>&& 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;

View file

@ -73,7 +73,8 @@ void VkLightmapper::ReleaseResources()
void VkLightmapper::SetLevelMesh(LevelMesh* level)
{
mesh = level;
UpdateAccelStructDescriptors();
if (mesh)
UpdateAccelStructDescriptors();
lightmapRaytraceLast.Reset();
lastPixelCount = 0;

View file

@ -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);