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

View file

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

View file

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

View file

@ -90,6 +90,7 @@ class DoomLevelMesh : public LevelMesh, public UpdateLevelMesh
{
public:
DoomLevelMesh(FLevelLocals &doomMap);
~DoomLevelMesh();
void PrintSurfaceInfo(const LevelMeshSurface* surface);