From 2901f31355a22279f7c96c17bea13a9373356c28 Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Wed, 22 May 2024 10:29:56 +0200 Subject: [PATCH] Invalidate actor light trace cache and fix possible nullptr exceptions --- src/playsim/actor.h | 5 +++++ src/rendering/hwrenderer/doom_levelmesh.cpp | 22 +++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 4cb0cd60b..9c9d1daa2 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1642,6 +1642,11 @@ public: DVector3 Pos = DVector3(-12345678.0, -12345678.0, -12345678.0); uint64_t Bits = 0; } StaticLightsTraceCache; + + void InvalidateLightTraceCache() + { + StaticLightsTraceCache.Pos.X = -1e80; + } }; class FActorIterator diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 8e2a7399a..2ed4e59fe 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -1190,10 +1190,21 @@ void DoomLevelMesh::CreatePortals(FLevelLocals& doomMap) // struct lightmap +static void InvalidateActorLightTraceCache() +{ + auto it = level.GetThinkerIterator(); + 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; } \ No newline at end of file