From 93ff380730755bdad704d702465e47e59aec0e3c Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 3 Feb 2024 00:53:06 -0800 Subject: [PATCH] Clear g_dc each frame I was running into a memcpy of overlapping memory regions in R_RenderMaskedSegRange. - This is because of the reallocation of lightlists, which uses Z_Frame_Alloc. - The memory pool that Z_Frame_Alloc draws from is cleared each frame. - g_dc was not cleared though, so when the lightlists were reallocated, it'd try to copy from invalidated pointers. - Access to invalid pointers within the memory pool does not cause a segfault directly (because the memory pool is allocated once). However, a memcpy involving such an invalid pointer leads to overlap, which may cause memory corruption. --- src/d_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index 4bd5caee2..7dee5488f 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -856,6 +856,7 @@ void D_SRB2Loop(void) precise_t enterprecise = I_GetPreciseTime(); precise_t finishprecise = enterprecise; + g_dc = {}; Z_Frame_Reset(); {