Skip to content

[OpenGL] g_pGamePersistent is null during initialization of render_rain #1807

@AMS21

Description

@AMS21

Describe the bug
g_pGamePersistent is null during initialization of render_rain

To Reproduce
Steps to reproduce the behavior:

  1. Apply the following patch or run with the undefined behavior sanitizer.
diff --git a/src/Layers/xrRender/light.cpp b/src/Layers/xrRender/light.cpp
index 03ba99f39..81265ce9d 100644
--- a/src/Layers/xrRender/light.cpp
+++ b/src/Layers/xrRender/light.cpp
@@ -7,6 +7,8 @@ static constexpr float RSQRTDIV2 = 0.70710678118654752440084436210485f;
 
 light::light() : SpatialBase(g_pGamePersistent->SpatialSpace)
 {
+    VERIFY(g_pGamePersistent);
+
     spatial.type = STYPE_LIGHTSOURCE;
     flags.type = POINT;
     flags.bStatic = false;
  1. Start the game
  2. See error

Expected behavior
Not reading from null pointers.

Screenshots, videos
N/A

BugTrap error report
Message from UBSAN:
/mnt/data/dev/xray-16/src/Layers/xrRender/light.cpp:8:49: runtime error: member access within null pointer of type 'struct IGame_Persistent'

Crash from the patch above:
FATAL ERROR

[error] Expression : g_pGamePersistent
[error] Function : light
[error] File : /mnt/data/dev/xray-16/src/Layers/xrRender/light.cpp
[error] Line : 10
[error] Description : assertion failed

stack trace:

xrDebug::Fail(bool&, ErrorLocation const&, char const*, char const*, char const*, char const*)
xray::render::render_gl::light::light()
/mnt/data/dev/xray-16/bin/x86_64/Debug/xrRender_GL.so(+0x244c0b8) [0x7ffff504c0b8]
xray::render::render_gl::CRender::CRender()
/mnt/data/dev/xray-16/bin/x86_64/Debug/xrRender_GL.so(+0x24a580d) [0x7ffff50a580d]
/mnt/data/dev/xray-16/bin/x86_64/Debug/xrRender_GL.so(+0x24a5932) [0x7ffff50a5932]
/mnt/data/dev/xray-16/bin/x86_64/Debug/xrRender_GL.so(+0x2be59f5) [0x7ffff57e59f5]
/lib64/ld-linux-x86-64.so.2(+0x549e) [0x7ffff7fc949e]
/lib64/ld-linux-x86-64.so.2(+0x55a3) [0x7ffff7fc95a3]
/lib64/ld-linux-x86-64.so.2(+0x20b60) [0x7ffff7fe4b60]

Stack trace from gdb:
xrRender_GL.so!xray::render::render_gl::light::light(xray::render::render_gl::light * const this) (/mnt/data/dev/xray-16/src/Layers/xrRender/light.cpp:10)
xrRender_GL.so!xray::render::render_gl::render_rain::render_rain(xray::render::render_gl::render_rain * const this) (/mnt/data/dev/xray-16/src/Layers/xrRender_R2/r2.h:121)
xrRender_GL.so!xray::render::render_gl::CRender::CRender(xray::render::render_gl::CRender * const this) (/mnt/data/dev/xray-16/src/Layers/xrRender_R2/r2.cpp:865)
xrRender_GL.so!__static_initialization_and_destruction_0() (/mnt/data/dev/xray-16/src/Layers/xrRender_R2/r2.cpp:20)
xrRender_GL.so!_GLOBAL__sub_I_r2.cpp(void)() (/mnt/data/dev/xray-16/src/Layers/xrRender_R2/r2.cpp:892)
xrRender_GL.so!_sub_I_65535_0.0 (Unknown Source:0)
ld-linux-x86-64.so.2![Unknown/Just-In-Time compiled code] (Unknown Source:0)

Desktop (please complete the following information):

  • OS: Linux 6.13.5-2-cachyos
  • OpenXRay build version d62c9b6

Additional context
Possibly introduced with 1efa85e

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions