blue-nebula / base

Main repository of Blue Nebula, a fast-paced shooter with a unique parkour system. It is a fork of Red Eclipse and is free software.
https://blue-nebula.org
15 stars 6 forks source link

Unable to run with clang + CMAKE_BUILD_TYPE=Release #247

Closed voidanix closed 2 years ago

voidanix commented 2 years ago

First seen in: master

Observation: when compiled with clang, the player preview in the menu is not rendered and the game crashes when pressing either the "play offline/online" buttons, OTOH the build works fine without the Release build type (and consequently the flags it applies).

Funnily enough, the same issue seems to affect RE2 (for which I have ported BN's cmake system) and it crashes immediatly after startup when it tries to display the player preview/model.

How to reproduce:

  1. CC=clang CXX=clang++ cmake . -DCMAKE_BUILD_TYPE=Release
    make -j$(nproc)
  2. Run the game and see the absent player preview.

  3. Press the "Offline practice" or "Play online" buttons for the game to crash

BN trace: ```shell (gdb) r Starting program: /bn/bin/blue-nebula_linux [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7ffff6f25640 (LWP 14607)] [New Thread 0x7fffe11fa640 (LWP 14614)] [New Thread 0x7fffe09f9640 (LWP 14615)] [New Thread 0x7fffd3fff640 (LWP 14616)] [New Thread 0x7fffd37fe640 (LWP 14617)] [New Thread 0x7fffd2ffd640 (LWP 14618)] [New Thread 0x7fffd27fc640 (LWP 14619)] [New Thread 0x7fffd1ffb640 (LWP 14620)] [New Thread 0x7fffd17fa640 (LWP 14621)] [Thread 0x7fffd17fa640 (LWP 14621) exited] [New Thread 0x7fffd17fa640 (LWP 14622)] [Thread 0x7fffd17fa640 (LWP 14622) exited] [New Thread 0x7fffd0c55640 (LWP 14624)] [New Thread 0x7fffd17fa640 (LWP 14625)] [Thread 0x7fffd17fa640 (LWP 14625) exited] [New Thread 0x7fffd17fa640 (LWP 14626)] [New Thread 0x7fffb7cff640 (LWP 14627)] libpng warning: iCCP: known incorrect sRGB profile Thread 1 "blue-nebula_lin" received signal SIGSEGV, Segmentation fault. 0x00000000004fa915 in ui_background (colour1=0x7fffffff8030, blend1=0x7fffffff8040, colour2=, blend2=, skinborder=0x4eaff80, levels=0x0) at engine/menus.cpp:374 374 if(cgui) cgui->background(*colour1, *blend1, *colour2, *blend2, *skinborder!=0, *levels); (gdb) where #0 0x00000000004fa915 in ui_background (colour1=0x7fffffff8030, blend1=0x7fffffff8040, colour2=, blend2=, skinborder=0x4eaff80, levels=0x0) at engine/menus.cpp:374 #1 0x00000000004a99ab in runcode (code=0x4eb3348, result=...) at engine/command.cpp:2160 #2 0x00000000004a9962 in runcode (code=0x4eb3350, code@entry=0x4eb32e0, result=...) at engine/command.cpp:2160 #3 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x4eb32e0) at engine/command.cpp:2364 #4 0x00000000004fcf80 in ui_list (contents=0x4eb32e0) at engine/menus.cpp:659 #5 0x00000000004a9910 in runcode (code=0x4eb481c, code@entry=0x4eb327c, result=...) at engine/command.cpp:2160 #6 0x00000000004ae9a3 in execute (code=0x4eb327c) at engine/command.cpp:2364 #7 looplist (id=0xa409c0, list=, body=0x4eb327c) at engine/command.cpp:2914 #8 0x00000000004a9962 in runcode (code=0x4eb4824, code@entry=0x4eb324c, result=...) at engine/command.cpp:2160 #9 0x00000000004aaf6a in runcode (code=0x4eb324c, code@entry=0x4eb3244, result=...) at engine/command.cpp:1954 #10 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x4eb3244) at engine/command.cpp:2364 #11 0x00000000004fcf80 in ui_list (contents=0x4eb3244) at engine/menus.cpp:659 #12 0x00000000004a9910 in runcode (code=0x4eb4b5c, code@entry=0x4eb323c, result=...) at engine/command.cpp:2160 #13 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x4eb323c) at engine/command.cpp:2364 #14 0x00000000004fcf80 in ui_list (contents=0x4eb323c) at engine/menus.cpp:659 #15 0x00000000004a9910 in runcode (code=0x4eb4bcc, code@entry=0x4eb3234, result=...) at engine/command.cpp:2160 #16 0x00000000004aa898 in runcode (code=0x35134d0, result=...) at engine/command.cpp:2253 #17 0x00000000004a9962 in runcode (code=0x35134d8, code@entry=0x3512ef0, result=...) at engine/command.cpp:2160 #18 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x3512ef0) at engine/command.cpp:2364 #19 0x00000000004fcf80 in ui_list (contents=0x3512ef0) at engine/menus.cpp:659 #20 0x00000000004a9910 in runcode (code=0x3513538, code@entry=0x351204c, result=...) at engine/command.cpp:2160 #21 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x351204c) at engine/command.cpp:2364 #22 0x00000000004fcf80 in ui_list (contents=0x351204c) at engine/menus.cpp:659 #23 0x00000000004a9910 in runcode (code=0x3513540, code@entry=0x3512034, result=...) at engine/command.cpp:2160 #24 0x00000000004ab58d in execute (code=0x173c120, code@entry=0x3512034) at engine/command.cpp:2364 #25 0x00000000005c535a in octapaks (contents=0x173c120) at engine/server.cpp:1522 #26 0x00000000004a9910 in runcode (code=0x35139cc, result=...) at engine/command.cpp:2160 #27 0x00000000004ab58d in execute (code=0x173c120) at engine/command.cpp:2364 #28 0x00000000004f9e83 in ui_stay_open (contents=0x173c120) at engine/menus.cpp:227 #29 0x00000000004a9910 in runcode (code=0x35139d4, result=...) at engine/command.cpp:2160 #30 0x00000000004ab58d in execute (code=0x173c120) at engine/command.cpp:2364 #31 0x00000000004ff1d7 in menu::gui (this=0x35040b0, g=..., firstpass=) at engine/menus.cpp:31 #32 0x00000000005f6a54 in UI::render () at engine/ui.cpp:1428 #33 0x000000000068e41e in hud::drawlast () at game/hud.cpp:1763 #34 0x0000000000553b9d in drawnoviewtype (targtype=2) at engine/rendergl.cpp:2012 #35 0x0000000000553cec in drawnoview () at engine/rendergl.cpp:2037 #36 0x000000000055476b in gl_drawframe () at engine/rendergl.cpp:2239 #37 0x00000000004ef2b3 in main (argc=, argv=) at engine/main.cpp:1152 ```
RE2 trace (just in case it ends up being related): ```shell (gdb) r Starting program: /testeclipse/bin/blue-nebula_linux [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". 2021-12-12 19:42.13 Checking working directory: /testeclipse 2021-12-12 19:42.13 Added package: data/ [New Thread 0x7ffff6f14640 (LWP 15846)] [New Thread 0x7fffe11e9640 (LWP 15849)] [New Thread 0x7fffe09e8640 (LWP 15850)] [New Thread 0x7fffdbfff640 (LWP 15851)] [New Thread 0x7fffdb7fe640 (LWP 15852)] [New Thread 0x7fffdaffd640 (LWP 15853)] [New Thread 0x7fffda7fc640 (LWP 15854)] [New Thread 0x7fffd9ffb640 (LWP 15855)] [New Thread 0x7fffd97fa640 (LWP 15858)] [Thread 0x7fffd97fa640 (LWP 15858) exited] [New Thread 0x7fffd97fa640 (LWP 15859)] [Thread 0x7fffd97fa640 (LWP 15859) exited] [New Thread 0x7fffd8c33640 (LWP 15861)] [New Thread 0x7fffd97fa640 (LWP 15862)] [Thread 0x7fffd97fa640 (LWP 15862) exited] [New Thread 0x7fffd97fa640 (LWP 15863)] [New Thread 0x7fffb7dff640 (LWP 15864)] free(): invalid pointer Thread 1 "blue-nebula_lin" received signal SIGABRT, Aborted. 0x00007ffff787a4ec in __pthread_kill_implementation () from /lib64/libc.so.6 (gdb) where #0 0x00007ffff787a4ec in __pthread_kill_implementation () from /lib64/libc.so.6 #1 0x00007ffff782d696 in raise () from /lib64/libc.so.6 #2 0x00007ffff78177f3 in abort () from /lib64/libc.so.6 #3 0x00007ffff786e627 in __libc_message () from /lib64/libc.so.6 #4 0x00007ffff788442c in malloc_printerr () from /lib64/libc.so.6 #5 0x00007ffff7885d3c in _int_free () from /lib64/libc.so.6 #6 0x00007ffff78887c5 in free () from /lib64/libc.so.6 #7 0x0000000000516415 in freearg (v=...) at engine/command.cpp:101 #8 freeargs (args=0x7fffffffc1a0, oldnum=@0x7fffffffc144: 2, newnum=-2) at engine/command.cpp:101 #9 runcode (code=0x85c8f3c, result=...) at engine/command.cpp:3063 #10 0x000000000051a337 in execute ( p=p@entry=0x855e5b0 "iqmdir \"actors/player\"\n\nexec \"actors/player/ragdoll.cfg\"\n\niqmtag hand.R tag_weapon 0.1 -0.9 0.1 -90 0 -90\niqmtag ribs tag_bjet 0 0.4 2\niqmtag shin.L.02 tag_ljet 0 -1.6 1.6\niqmtag shin.R.02 tag_rjet 0 "...) at engine/command.cpp:3394 #11 0x000000000051ad55 in execfile (cfgfile=0x8552160 "actors/player/player.cfg", msg=, flags=0) at engine/command.cpp:3507 #12 0x000000000051ade2 in _icmd_exec<3516>::run (file=0x3de2 , flags=, msg=) at engine/command.cpp:3516 #13 0x000000000051432a in runcode (code=0x855218c, result=...) at engine/command.cpp:3061 #14 0x000000000051a337 in execute (p=p@entry=0x8550f90 "iqmload \"hud-body.iqm\" player\nexec \"actors/player/player.cfg\"\n\nmdllod lod1 128\nmdllod lod2 512") at engine/command.cpp:3394 #15 0x000000000051ad55 in execfile (cfgfile=cfgfile@entry=0x7fffffffd0b0 "actors/player/male/headless/iqm.cfg", msg=, flags=flags@entry=0) at engine/command.cpp:3507 #16 0x00000000006279a7 in modelloader::loadconfig (this=) at engine/animmodel.h:2100 #17 0x0000000000600e2b in animmodel::load (this=0x854ceb0) at engine/animmodel.h:1737 #18 0x00000000005f6bcb in loadmodel (name=name@entry=0x853613 "actors/player/male/headless", i=i@entry=-1, msg=false) at engine/rendermodel.cpp:510 #19 0x00000000005f9a90 in rendermodel (mdl=0x3de2 , mdl@entry=0x853613 "actors/player/male/headless", state=..., d=d@entry=0x8552430) at engine/rendermodel.cpp:1064 #20 0x000000000076c09a in game::renderplayer (d=0x8552430, third=third@entry=1, size=size@entry=1, flags=, flags@entry=0, color=..., lastoffset=, lastoffset@entry=0x0) at game/game.cpp:3930 #21 0x000000000076db02 in game::renderplayerpreview (scale=1, mcolor=..., actions=0x84f59f0 "\n", ' ' , "uiplayerpreviewmodel (getplayermodel)\n", ' ' , "uiplayerpreviewpattern (getplayerpattern)\n", ' ' , "uiplayerpreviewcolour (getplayercolour -1)\n", ' ' , "uiplayerprev"..., yaw=12.5, offsetyaw=0) at game/game.cpp:4065 #22 0x00000000006dd72f in UI::PlayerPreview::draw (this=0x84f5870, sx=0.428888917, sy=0.125000015) at engine/ui.cpp:4275 #23 0x00000000006cc896 in UI::Object::draw (this=0x84f57d0, sx=, sy=) at engine/ui.cpp:583 #24 0x00000000006cc896 in UI::Object::draw (this=0x55aac00, sx=, sy=) at engine/ui.cpp:583 #25 0x00000000006cc896 in UI::Object::draw (this=0x58545b0, sx=, sy=) at engine/ui.cpp:583 #26 0x00000000006cc896 in UI::Object::draw (this=0x5864a40, sx=, sy=) at engine/ui.cpp:583 #27 0x00000000006cbf06 in UI::Object::draw (this=0x513e550, sx=0, sy=0) at engine/ui.cpp:583 #28 UI::Window::draw (this=0x513e550, sx=, sy=) at engine/ui.cpp:877 #29 0x00000000006c9ec4 in UI::Window::draw (this=0x3de2) at engine/ui.cpp:888 #30 UI::World::draw (this=0x1aa3f50) at engine/ui.cpp:1137 #31 0x00000000006c108a in UI::render () at engine/ui.cpp:4999 #32 0x000000000077dc51 in hud::render (noview=) at game/hud.cpp:1820 #33 0x00000000005c68bc in gl_drawhud (noview=true) at engine/rendergl.cpp:2529 #34 0x00000000005c6be2 in gl_drawframe () at engine/rendergl.cpp:2574 #35 0x0000000000562109 in main (argc=, argv=) at engine/main.cpp:1202 ```

I initially saw this bug a few months ago but just blamed the compiler being too new (clang-13.0.0-rc1), but with stable clang 13.0.0 the issue persists; a friend of mine also told me that on OpenBSD the issue does not seem exist.

I searched the issue list and checked that this is not a duplicate :white_check_mark: I tried to rename my config.cfg, and the problem also occurs with default settings :white_check_mark:

TheAssassin commented 2 years ago

Have you tried gcc and/or older clang releases?

voidanix commented 2 years ago

GCC works fine, did not try with older clang releases (but I think the crash is reproducible on 12.0.0)

voidanix commented 2 years ago

@TheAssassin as discussed on IRC, here is the patch that makes things not crash:

diff --git a/src/engine/menus.cpp b/src/engine/menus.cpp
index faa3f08..79ea74a 100644
--- a/src/engine/menus.cpp
+++ b/src/engine/menus.cpp
@@ -713,7 +713,7 @@ COMMAND(0, ui_body, "esse");
 COMMAND(0, ui_bar, "iibb");
 COMMAND(0, ui_fill, "ii");
 COMMAND(0, ui_outline, "iiii");
-COMMAND(0, ui_background, "bgbgii");
+COMMAND(0, ui_background, "bfbfii");
 COMMAND(0, ui_strut, "fi");
 COMMAND(0, ui_spring, "i");
 COMMAND(0, ui_visible, "e");

The magic letters come from the specifiers of the arguments in the ui_background function, I think:

void ui_background(int *colour1, float *blend1, int *colour2, float *blend2, int *skinborder, int *levels)

Trying to replace with f one of the floats individually still leads to the crash.

EDIT: not dereferencing one of the floats also seems to work:

diff --git a/src/engine/menus.cpp b/src/engine/menus.cpp
index faa3f08..277aff1 100644
--- a/src/engine/menus.cpp
+++ b/src/engine/menus.cpp
@@ -369,9 +369,9 @@ void ui_outline(int *colour, int *levels, int *offsetx, int *offsety)
     if(cgui) cgui->outline(*colour, *levels, 0, *offsetx, *offsety);
 }

-void ui_background(int *colour1, float *blend1, int *colour2, float *blend2, int *skinborder, int *levels)
+void ui_background(int *colour1, float *blend1, int *colour2, float blend2, int *skinborder, int *levels)
 {
-    if(cgui) cgui->background(*colour1, *blend1, *colour2, *blend2, *skinborder!=0, *levels);
+    if(cgui) cgui->background(*colour1, *blend1, *colour2, blend2, *skinborder!=0, *levels);
 }

 void ui_strut(float *strut, int *alt)
robalni commented 2 years ago

I don't get any crash or player preview issues on clang 11 (the current one in Debian stable).

voidanix commented 2 years ago

After spinning up multiple containers/VMs, this one looks (to me) like a regression in clang 13.0.0 specifically.

Both clang main and <=12 work just fine so I am really out of ideas as to what is going on.

I am probably going to keep the issue open until 13.0.1 comes out (if it fixes the issue) so we could probably get more feedback when on 13.0.0.

TheAssassin commented 2 years ago

Fascinating. I'll try to reproduce this on some Ubuntu bionic later, clang is compiling already.

TheAssassin commented 2 years ago

For the record, reproducible only with clang 13.0.0. I'd also say it's a compiler bug of some kind. I don't think it's worth spending more time on debugging. Please avoid 13.0.0 specifically.