OpenXRay / OpenXRay/xray-16

[OpenGL] `g_pGamePersistent` is null during initialization of `render_rain`

Open
#1,807 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Code Quality Renderer
Dominant language
C++
Stars
3.6k
Forks
536
Avg merge
6d 1h
Merged PRs (30d)
3

Description

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 d62c9b65e11ea0f2754c9e561e5f04ca6a3259b5

Additional context
Possibly introduced with 1efa85e6c8dd60b09d15b3d738590dc674a4b333

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Layers/xrRender/light.cpp and trace the render_rain construction from src/Layers/xrRender_R2/r2.h and r2.cpp. Reproduce the startup with UBSAN and inspect the static initialization path shown in the report. Done means initialization no longer reads g_pGamePersistent through a null pointer and the game starts without the reported sanitizer error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.