pioneerspacesim/pioneer — Issue #885: Timer:CallEvery() causes a segfault if called before game start
Author: johnbartholomew
Created: 2012-01-06 15:36:36+00:00
State: open
Labels: Crash or hang

Test script:

local something = function () end
Timer:CallEvery(30.0, something)

Back-trace:

0x000000000042037c in Game::GetTime (this=0x0) at ../../pioneer/src/Game.h:34
34	double GetTime() const { return m_time; }
(gdb) bt
#0 0x000000000042037c in Game::GetTime (this=0x0) at ../../pioneer/src/Game.h:34
#1 0x00000000004dd3a0 in l_timer_call_every (l=0x1141ba0) at ../../pioneer/src/LuaTimer.cpp:222
#2 0x000000000062708e in luaD_precall (L=0x1141ba0, func=0x11ab780, nresults=0)
at ../../../pioneer/contrib/lua/ldo.c:319
#3 0x000000000063c3bb in luaV_execute (L=0x1141ba0, nexeccalls=1) at ../../../pioneer/contrib/lua/lvm.c:590
#4 0x0000000000627339 in luaD_call (L=0x1141ba0, func=0x11ab760, nResults=0)
at ../../../pioneer/contrib/lua/ldo.c:377
#5 0x000000000062200d in f_call (L=0x1141ba0, ud=0x7fffffffdbe0) at ../../../pioneer/contrib/lua/lapi.c:800
#6 0x00000000006262ac in luaD_rawrunprotected (L=0x1141ba0, f=0x621fd8 , ud=0x7fffffffdbe0)
at ../../../pioneer/contrib/lua/ldo.c:116
#7 0x0000000000627743 in luaD_pcall (L=0x1141ba0, func=0x621fd8 , u=0x7fffffffdbe0, old_top=32,
ef=16) at ../../../pioneer/contrib/lua/ldo.c:463
#8 0x00000000006220b6 in lua_pcall (L=0x1141ba0, nargs=0, nresults=0, errfunc=-2)
at ../../../pioneer/contrib/lua/lapi.c:821
#9 0x00000000004de1ac in pi_lua_dofile_recursive (l=0x1141ba0, basepath=...)
at ../../pioneer/src/LuaUtils.cpp:124
#10 0x00000000004e7e7b in LuaInit () at ../../pioneer/src/Pi.cpp:278
#11 0x00000000004e8e03 in Pi::Init () at ../../pioneer/src/Pi.cpp:499
#12 0x00000000005a3387 in main (argc=1) at ../../pioneer/src/main.cpp:17

Thanks to m4r35n357 for finding this and producing a reduced test case.

Note to scripters: You can avoid this by starting your timers from an onGameStart event handler. That is the right thing to do anyway, as timer functions will probably be disabled before game-start anyway.