Invalidate actor light trace cache and fix possible nullptr exceptions

This commit is contained in:
RaveYard 2024-05-22 10:29:56 +02:00
commit 2901f31355
2 changed files with 23 additions and 4 deletions

View file

@ -1190,10 +1190,21 @@ void DoomLevelMesh::CreatePortals(FLevelLocals& doomMap)
// struct lightmap
static void InvalidateActorLightTraceCache()
{
auto it = level.GetThinkerIterator<AActor>();
AActor* ac;
while ((ac = it.Next()))
{
ac->InvalidateLightTraceCache();
}
}
DEFINE_ACTION_FUNCTION(_Lightmap, Invalidate)
{
PARAM_PROLOGUE;
InvalidateLightmap();
InvalidateActorLightTraceCache();
return 0;
}
@ -1206,7 +1217,7 @@ DEFINE_ACTION_FUNCTION(_Lightmap, SetSunDirection)
auto vec = FVector3(float(x), float(y), float(z));
if (!vec.isZero())
if (!vec.isZero() && level.levelMesh)
{
vec.MakeUnit();
level.SunDirection = vec;
@ -1222,8 +1233,11 @@ DEFINE_ACTION_FUNCTION(_Lightmap, SetSunColor)
PARAM_FLOAT(y);
PARAM_FLOAT(z);
auto vec = FVector3(float(x), float(y), float(z));
level.SunColor = vec;
level.levelMesh->SunColor = vec;
if (level.levelMesh)
{
auto vec = FVector3(float(x), float(y), float(z));
level.SunColor = vec;
level.levelMesh->SunColor = vec;
}
return 0;
}