Aleph-One-Marathon / alephone

Aleph One is the open source continuation of Bungie’s Marathon 2 game engine.
https://alephone.lhowon.org/
GNU General Public License v3.0
621 stars 100 forks source link

Crash when using Lua to create objects set to “display a random frame” with zero frames per view #461

Open aaronfreed opened 5 months ago

aaronfreed commented 5 months ago

i discovered last night that if you try to use Lua to create a scenery item with a sequence set to “display a random frame” with zero frames per view (i’m a dingus and forgot to save my shapes file), the game crashes without explanation (on Windows, Linux, and presumably Intel Macs, at least) due to a floating-point exception (i.e., division by zero). this line in map.cpp appears to be the culprit:

global_random()%animation->frames_per_view

here’s the top of a stack trace that Solra ran in Valgrind:

#0  0x0000555555624af3 in randomize_object_sequence(short, unsigned short)
    (object_index=object_index@entry=109, shape=<optimized out>)
    at map.cpp:1147
#1  0x0000555555644969 in randomize_scenery_shape(short)
    (object_index=<optimized out>, object_index@entry=109) at scenery.cpp:143
#2  0x00005555556da2b3 in Lua_Sceneries_New(lua_State*) (L=0x55555673e010)
    at lua_objects.cpp:768

i’m guessing this problem also occurs with items, ephemera, effects, and possibly monsters, though i haven’t actually confirmed this.

in any case, i plan to make a PR that makes an assertion to detect this error and present a helpful error message rather than crash without explanation, so that the next time someone has this problem, they don’t waste five hours of their life thinking faulty Lua caused the crash. not that i know anyone this has happened to. shifty-eyes-ani

(thanks to Solra for the stack trace and for identifying the line that was causing the issue.)