bug in player death, and other bug in newgamemenu.cpp

Install & setup problems, application questions and other nasty things ;)

Moderators: Frustikus, simX, Aus-RED-5

eigenlambda
Posts: 5
Joined: Wed Jan 28, 2015 6:08 am

bug in player death, and other bug in newgamemenu.cpp

Postby eigenlambda » Mon Feb 16, 2015 12:03 am

I've been experiencing this weird bug wherein when the player dies he drops as many copies of the items he carries as possible until there is no free space left in the object array, so then when he respawns neither he nor his robot friends can fire their weapons.

I tried adding this guard to DropPlayerEggs() -

static fix lastDropTime = 0;
static int numDrops = 0;
if (lastDropTime < gameData.time.xGame + I2X(1))
{
lastDropTime = gameData.time.xGame;
numDrops = 0;
}
else {
lastDropTime = gameData.time.xGame;
numDrops++;
if (numDrops >= 20)
return;
}

which works out okay

Also, it looks like when lightmaps mode was added to newgamemenu.cpp, an 'else if' clause got misplaced.
else if (!gameStates.app.bComputeLightmaps) {
i = m.ToInt ("initial lives");
if (i > 0)
gameStates.gameplay.nInitialLives = Min (i, 255);
}
}
Personally I think it should be put before the i = m.Value("difficulty"); and I guess like guarded by #ifdef DEBUG or whatever.

cheers,
~thomas :laola:
eigenlambda
Posts: 5
Joined: Wed Jan 28, 2015 6:08 am

Re: bug in player death, and other bug in newgamemenu.cpp

Postby eigenlambda » Mon Feb 16, 2015 3:11 am

update: turns out it didn't work. So either my logic was faulty, or the player drops stuff somewhere else in the code as well. :( i'm not sure how to debug something when i don't know where it is in the program maybe i can set a breakpoint where it discovers that it can't make another object?
eigenlambda
Posts: 5
Joined: Wed Jan 28, 2015 6:08 am

Re: bug in player death, and other bug in newgamemenu.cpp

Postby eigenlambda » Tue Feb 17, 2015 8:39 am

If this happens to anyone else, DropPlayerEggs can be guarded by

static fix lastDropTime = 0;
if (lastDropTime + I2X(1) < gameData.time.xGame)
{
lastDropTime = gameData.time.xGame;
}
else {
lastDropTime = gameData.time.xGame;
return;
}

That's a stupid hack. DropPlayerEggs gets called from something that gets called from DeadPlayerFrame. Every frame while something and not something else, the DestroyPlayerShip() on line 224 happens. I don't know enough about the code to know how to ensure it only happens once by fixing it there.
Sirius
Posts: 1990
Joined: Tue Sep 25, 2007 10:29 pm
Location: Bellevue, WA
Contact:

Re: bug in player death, and other bug in newgamemenu.cpp

Postby Sirius » Tue Feb 17, 2015 8:48 am

Yeah, the right solution is definitely to prevent this function being called multiple times - it doesn't make logical sense for that to happen. But game loops can be complicated things.
User avatar
karx11erx
D2X-XL Master
D2X-XL Master
Posts: 8112
Joined: Mon Sep 24, 2007 8:48 pm
Location: Wilferdingen, Germany
Contact:

Re: bug in player death, and other bug in newgamemenu.cpp

Postby karx11erx » Tue Feb 17, 2015 7:17 pm

I would like to know how to reproduce that bug, because the proper solution here is not to hack an ugly fix involving globally declared static variables, but to remove the underlying issue. DestroyPlayerShip() only gets called from line 244 of playerdeath.cpp if LOCALPLAYER.m_bExploded == 0. DestroyPlayerShip() sets LOCALPLAYER.m_bExploded to 1. So something needs to set LOCALPLAYER.m_bExploded to 0 again after DestroyPlayerShip() has been called from DeadPlayerFrame().

The lightmap precalculation code in newgamemenu looks correct to me.
eigenlambda
Posts: 5
Joined: Wed Jan 28, 2015 6:08 am

Re: bug in player death, and other bug in newgamemenu.cpp

Postby eigenlambda » Wed Feb 18, 2015 2:09 am

i see. my shield regen hack was interacting badly with UpdateDeathTime() :oops:
Sirius
Posts: 1990
Joined: Tue Sep 25, 2007 10:29 pm
Location: Bellevue, WA
Contact:

Re: bug in player death, and other bug in newgamemenu.cpp

Postby Sirius » Wed Feb 18, 2015 7:59 am

Yep, that would be why modifying D2X-XL without being very very careful is dangerous :pop:
User avatar
karx11erx
D2X-XL Master
D2X-XL Master
Posts: 8112
Joined: Mon Sep 24, 2007 8:48 pm
Location: Wilferdingen, Germany
Contact:

Re: bug in player death, and other bug in newgamemenu.cpp

Postby karx11erx » Wed Feb 18, 2015 4:50 pm

eigenlambda wrote:i see. my shield regen hack was interacting badly with UpdateDeathTime() :oops:


Trololo! :rofl:

You may want to check gameStates.app.bPlayerIsDead in your shield regen hack. Another problem you might have with that hack is in multiplayer games. You may want to check IsMultiGame, too.

Return to “D2X-XL Help”

Who is online

Users browsing this forum: No registered users and 3 guests