Menu

#19 Uninitialized variable leads to crashes

open
nobody
None
9
2006-06-20
2006-06-19
No

I finally tracked this one down. It was causing
occasional crashes and weird effects, but only in
release builds, and it took a while to find.

In Action.h, one of the three constructors of
TimedAction does not initialize the member
variable "valid". This causes some Actions added to
the queue via Game::AddActionRelative() and
Game::AddActionAbsolute() -- among other code paths --
to occasionally drop Actions. These do not cause a
memory leak, but they can lead to commands being
ignored, breaks in combat, and, depending on how your
logics are set up, possibly to crashes.

To fix:
search in Action.h for the third and final
TimedAction constructor. It looks like this:

TimedAction(
BasicLib::sint64 time,
const std::string& p_action,
entityid p_data1 = 0,
entityid p_data2 = 0,
entityid p_data3 = 0,
entityid p_data4 = 0,
const std::string& p_data = "" ) :
executiontime( time ),
actionevent( p_action, p_data1, p_data2, p_data3,
p_data4, p_data ) {}

Make it also initialize the valid variable to true,
like this:

TimedAction(
BasicLib::sint64 time,
const std::string& p_action,
entityid p_data1 = 0,
entityid p_data2 = 0,
entityid p_data3 = 0,
entityid p_data4 = 0,
const std::string& p_data = "" ) :
executiontime( time ),
actionevent( p_action, p_data1, p_data2, p_data3,
p_data4, p_data ),
valid( true ) {}

Though this fix has helped reliability considerably,
I am not positive this is the source of all the
crashes in release mode. I'll add more bugs if I
track them down.

Discussion

  • Eric Heimburg

    Eric Heimburg - 2006-06-19

    Logged In: YES
    user_id=860892

    Ah, now I CAN trace this back to the crashes. Because
    these TimedAction *'s are AddHook()'ed into various
    objects, but are then deleted without ever being unhooked,
    they cause crashes whenever the object it was hooked into
    loops over its hooks (such as in LogicEntity::KillHook()).

    This is a serious error and I suspect it to be the cause
    of much bizarre behavior. Yay for fix. Go me.

     
  • Eric Heimburg

    Eric Heimburg - 2006-06-20
    • priority: 5 --> 9
     

Log in to post a comment.

Auth0 Logo