project-navigation
Personal tools

Author Topic: Reaction Fire - End Turn  (Read 7617 times)

Offline poida

  • Cannon Fodder
  • **
  • Posts: 5
    • View Profile
Reaction Fire - End Turn
« on: July 01, 2010, 01:09:00 pm »
Hi All,

Just discovered the game last week gr8 job all! I am having trouble in battlescape mode. It looks like the problem is related to reaction fire, but I can't be sure. Anyway, my turn keeps getting ended without me pressing 'e' or hitting the end turn button. If I press the right-mouse button it thinks it's not my turn, if I left click, it tries to cue up movement. The cursor stays on the hourglass too.

Here is some log:

2010/07/01 20:48:45 [STATS] poida (Naa'il Coffey) kills alien (Kraerak K Krokk) with Snap Shot - Airburst of grenl_incendiary_ammo
2010/07/01 20:49:26 [STATS] poida (Asiya Finet) kills alien (Abtrenek Uk Kronok) with Full-Auto of assault_ammo
2010/07/01 20:49:27 Team 1 ended round
2010/07/01 20:49:27 Team 0's round started!

If anyone can point me of the right direction in terms of code/breakpoints then I'll try and debug it.

Oh and I'm running ufoai 2.4-dev [30746] on Debian 5

Cheers,
poida

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: Reaction Fire - End Turn
« Reply #1 on: July 06, 2010, 11:17:59 pm »
Hi and welcome :)

What makes you think it might be related to raction fire ?

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Reaction Fire - End Turn
« Reply #2 on: July 06, 2010, 11:25:19 pm »
this was also already reported in the irc channel - but i'm not sure whether it is related to reactionfire.

is it someone reliable reproducible?

Offline poida

  • Cannon Fodder
  • **
  • Posts: 5
    • View Profile
Re: Reaction Fire - End Turn
« Reply #3 on: July 09, 2010, 08:17:22 pm »
I can't really be sure that it is reaction fire, but it always seems to happen when either I first spot an enemy, or they are doing reaction fire. The other weird thing is that it doesn't always happen. Not quite sure how it occurs, or how to reproduce.

Does anyone know how I could diagnose the problem? I have ufoai dev setup and could set breakpoints/step etc.

Offline Duke

  • Administrator
  • PHALANX veteran
  • *****
  • Posts: 1037
    • View Profile
Re: Reaction Fire - End Turn
« Reply #4 on: July 10, 2010, 12:50:16 am »
Does anyone know how I could diagnose the problem?
Sorry, no idea yet. Continue to observe and hopefully find some pattern.
How often does a turn end this way ?

Offline dodon

  • Rookie
  • ***
  • Posts: 48
    • View Profile
Re: Reaction Fire - End Turn
« Reply #5 on: July 15, 2010, 06:58:32 pm »
poida is right the bug is related to reaction fire. But it also is thread related. So it's not easy to reproduce.

Here is a ufoconsole.log with additional entries to show what happened:
Code: [Select]
2010/07/15 16:32:42 (player 0) It's team 1's round
2010/07/15 16:32:42 dodon has taken control over team 1.
2010/07/15 16:32:53 [STATS] dodon (Lorraine Checa S-2) kills alien (Morgh Hs Nhs Oorgh) with Snap Shot of sniper_ammo
2010/07/15 16:32:53 RF1 change active team to 7 Time:347406 Thread:4076
2010/07/15 16:32:53 AI  active (7)              Time:347406 Thread:3788
2010/07/15 16:32:53 RF2 change active team to 1 Time:347422 Thread:4076
2010/07/15 16:33:23 RF1 change active team to 7 Time:377409 Thread:4076
2010/07/15 16:33:23 AI  active (7)              Time:377409 Thread:3788
2010/07/15 16:33:23 RF2 change active team to 1 Time:377425 Thread:4076
2010/07/15 16:33:29 RF1 change active team to 7 Time:383042 Thread:4076
2010/07/15 16:33:29 AI  active (7)              Time:383042 Thread:3788
2010/07/15 16:33:29 RF2 change active team to 1 Time:383042 Thread:4076
2010/07/15 16:33:29 RF1 change active team to 7 Time:383043 Thread:4076
...
2010/07/15 16:33:29 RF2 change active team to 1 Time:383045 Thread:4076
2010/07/15 16:33:33 RF1 change active team to 7 Time:387177 Thread:4076
2010/07/15 16:33:33 AI  active (7)              Time:387177 Thread:3788
2010/07/15 16:33:33 RF2 change active team to 1 Time:387177 Thread:4076
...
2010/07/15 16:33:33 RF2 change active team to 1 Time:387199 Thread:4076
2010/07/15 16:33:41 RF1 change active team to 7 Time:395414 Thread:4076
2010/07/15 16:33:41 AI  active (7)              Time:395414 Thread:3788
2010/07/15 16:33:41 RF2 change active team to 1 Time:395414 Thread:4076
2010/07/15 16:33:41 RF1 change active team to 7 Time:395415 Thread:4076
...
2010/07/15 16:33:41 RF2 change active team to 1 Time:395418 Thread:4076
2010/07/15 16:33:41 RF1 change active team to 7 Time:395492 Thread:3788
2010/07/15 16:33:42 RF2 change active team to 1 Time:395606 Thread:3788
2010/07/15 16:33:42 AI  active (7)              Time:395721 Thread:3788
2010/07/15 16:33:42 AI  active (7)              Time:395874 Thread:3788
2010/07/15 16:33:42 AI  active (7)              Time:396072 Thread:3788
2010/07/15 16:33:42 AI  active (7)              Time:396241 Thread:3788
2010/07/15 16:33:42 AI  active (7)              Time:396403 Thread:3788
2010/07/15 16:33:42 AI  active (0)              Time:396498 Thread:3788
2010/07/15 16:33:43 AI  active (0)              Time:396634 Thread:3788
2010/07/15 16:33:43 AI  active (0)              Time:396777 Thread:3788
2010/07/15 16:33:43 AI  active (0)              Time:396883 Thread:3788
2010/07/15 16:33:43 AI  active (0)              Time:396996 Thread:3788
2010/07/15 16:33:43 AI  active (0)              Time:397109 Thread:3788
2010/07/15 16:33:44 Team 1 ended round
2010/07/15 16:33:44 Team 7's round started!
2010/07/15 16:33:56 Team 7 ended round
2010/07/15 16:33:56 Team 0's round started!
2010/07/15 16:33:56 Team 0 ended round
2010/07/15 16:33:56 Team 1's round started!
2010/07/15 16:36:07 quit
The code is trunk r31015 and the entry
  RF1 is from g_reaction.c line 360,
  RF2 is from g_reaction.c line 363 and
  AI is from g_ai.c line 1044

What happens is this:
A soldier from team 0 moves and an alien can shoot with RF, so th game changes sides to execute the shot. At the same time the thread with the alien AI checks which side is active and starts the AI. At that point several things can happen such as the alien shoots at a target unrelated to RF or the AI tells the server to change the sides (back to the alien team).



 

Offline fede

  • Rookie
  • ***
  • Posts: 15
    • View Profile
[30961] Re: Reaction Fire - End Turn
« Reply #6 on: July 17, 2010, 05:21:54 pm »
Hello, i'm new to this game and forum. Have played intensively for a week on dev version and i can confirm this bug. It is very annoying, i have to retry same missin many times due to hourglass in my own shift after a reaction fire and alien movements.
Finally i decided to report bugs (there are more, follow in other posts). I just experienced a crash that MIGHT be related with this bug. aliens were firing by reaction and i was expecting the usual hourglass but game crashed.
This is my shell output:
Code: [Select]
fede has taken control over team 1.
./ufo(Sys_Backtrace+0x1f)[0x81aa7a8]
./ufo(Sys_Error+0x22)[0x81a9d89]
./ufo[0x81557ed]
./ufo(_Mem_Free+0x30)[0x81558f5]
./ufo(free_dbuffer+0x94)[0x815a6c2]
./ufo(SV_Multicast+0x77)[0x817310e]
./ufo[0x816c6ed]
./ufo[0x816c73c]
./base/game.so(G_EventShootHidden+0x39)[0x27b1e9a]
./base/game.so(G_ClientShoot+0x75e)[0x27afab0]
./base/game.so(G_ClientAction+0x1b9)[0x27a9cb4]
./ufo(SV_ExecuteClientMessage+0x124)[0x817383c]
./ufo(SV_ReadPacket+0x60)[0x816e857]
./ufo(NET_Wait+0x296)[0x81574f2]
./ufo(Qcommon_Frame+0x12b)[0x814d734]
./ufo(main+0x5c)[0x81a99bf]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x1fbbd6]
./ufo[0x806cdc1]
Error: Mem_Free: bad memory header top sentinel [buffer underflow]
free: src/common/dbuffer.c:#166

Hope it gets fixed soon :)

(btw, do you use some platform like bugzilla to keep track of bugs? Couldn't find it in the site)
« Last Edit: July 17, 2010, 05:56:23 pm by fede »

Offline nonickch

  • Rookie
  • ***
  • Posts: 36
    • View Profile
Re: Reaction Fire - End Turn
« Reply #7 on: July 19, 2010, 10:53:58 am »
A few mins ago I saw something that fits a 'reaction fire triggers end of turn'.

I had debugger on with breakpoints on the AI functions and as I was moving my actors to some random positions my breakpoints started kicking in and the AI was fully running in the stacktrace.
For a moment I thought that RF kicks in the AI (and that I had missed some trunk RF changes), but this explanation seems more plausible.

update: it happened again and I think it's under the same circumstances:
I got one of my soldiers die from alien RF and in the same turn I moved another of my soldiers to a place where he could get rf'd.
The debugger kicked in on the G_ActionCheck if (TU > G_ActorUsableTUs(ent)){return qfalse;} (the lines which I guard with breakpoints) for about 5 times in a row while the stacktrace was still indicating RF-related function names.
But straight after that I landed in my pure AI breakpoints.
Log is squeaky clean.

Now that I also looked into it more closely, all the AI attempts to move/shoot get thrown out from G_ActionCheck because "level.activeTeam != player->pers.team". activeteam is still 1.
As far as I know, we should never have activeteam 1 AND call the AI to compute it's turn.

Maybe my experiences are something wrong I've done in my copy or maybe it's indicative of the problem. Just thought I'd share

Update:
Yes, this happens quite frequently. RF checks turn into AI's turn to move while console starts spamming 'Can't perform action - this isn't your round!' (I don't think I let the console flush before killing the process in the previously mentioned example). But this happens only on random intervals. I re-checked the AI and it only kicks in for "G_IsAIPlayer(player) && level.activeTeam == player->pers.team". Notice the disparity between starting the AI and G_ActionCheck returning false? The same expression evaluating differently without the AI ever touching the level.activeTeam or player->pers.team values.
I wouldn't know much about these, but it sounds like a thread issue.
Also I got a 'ufo: src/server/sv_world.c:423: SV_HullForEntity: Assertion `ent->solid != SOLID_TRIGGER' failed.' on the last happening. I remember someone complaining about this elsewhere, maybe they have a common root?
« Last Edit: July 20, 2010, 08:11:27 am by nonickch »

Offline nonickch

  • Rookie
  • ***
  • Posts: 36
    • View Profile
Re: Reaction Fire - End Turn
« Reply #8 on: July 21, 2010, 10:49:27 pm »
starting line 357 of g_reaction.c:
So yeah, this can explain everything,
Code: [Select]
/* Change active team for this shot only. */
team = level.activeTeam;
level.activeTeam = ent->team;

/* take the shot */
tookShot = G_ReactionFireShoot(G_PLAYER_FROM_ENT(ent), ent, ent->reactionTarget->pos, ST_RIGHT_REACTION, ent->chr.RFmode.fmIdx);

/* Revert active team. */
level.activeTeam = team;

Now, every 10 serverFrames, the AI code checks to find an actor to move like this:
Code: [Select]

if (level.framenum % 10)
return;

/* set players to ai players and cycle over all of them */
for (i = 0, player = game.players + game.sv_maxplayersperteam; i < game.sv_maxplayersperteam; i++, player++)
if (player->inuse && G_IsAIPlayer(player) && level.activeTeam == player->pers.team) {

if the AI thread interrupts the thread running the RF while it's taking a RF shot (assuming they are on different threads), then the activeTeam check is true, and I'm assuming the same goes for player->inuse. That will get the AI going. Now, IF all the aliens have next to 0 tu's, and given that the 2.3/current-trunk AI is quite fast, it will call for 'end of turn' once the for loop completes. It depends on the thread interleaving and that's why it's so hard to reproduce.

This is especially visible in my modified AI where it's execution time is currently very lengthy. RF[interrupted]->AI-start[interrupted]->RF[completes]->AI resumes thinking it's his turn. At this point it will try to make the alien shoot and the 'it's not your turn' will start swamping the log.

If this is really the problem, locking access to level or level.activeTeam while RF shooting should be enough (I have no idea how to do that). If there's a way for the AI to make sure RF is not going on at any given point, tell what to check for and I can fix this from the AI side.

UPDATE: Confirming that some kind of end of turn can be caused because of the RF & access to the level.activeTeam. I killed the AI by making it call end of turn as soon as it's about to start thinking for one of the aliens. Loaded up an open-space map and tried to move my squaddies. Result:
Code: [Select]
Team 1 ended round
Team 0's round started!
Team 0 ended round
Team 1's round started!

x12 !!!
And that's from a simple 20-TU walk in front of an alien. Notice that there's NO team 7 mentioned anywhere in there. Strange.
After moving around a little bit more and getting shot enough, the following strange occasion happened:
My squaddie "died" to RF getting the death animation, then promptly got up again, followed by crash with:
"ufo: src/client/battlescape/cl_actor.c:1779: CL_AddTargetingBox: Assertion `chr' failed."

This is different from all the other RF-related crashes I got, it's a different one every time. This is quite an important bug and we should get to it asap.
Unfortunately I have no idea how to mutex things.
« Last Edit: July 22, 2010, 08:45:12 am by nonickch »

Offline dodon

  • Rookie
  • ***
  • Posts: 48
    • View Profile
Re: Reaction Fire - End Turn
« Reply #9 on: July 23, 2010, 04:48:42 pm »
I can think of several ways to remove the bug:

1. blocking the AI with an extra var for the active team, that gets only changed, when the server gets a "end round" message
2. blocking the AI, while the reaction fire changes the active team.
3. refactoring the shootingfunctions, to remove the dependency on level.activeTeam

If someone of the developers pionts out the desired (or a better) solution, i'll provide the necessary code.

Offline dodon

  • Rookie
  • ***
  • Posts: 48
    • View Profile
Re: Reaction Fire - End Turn
« Reply #10 on: July 27, 2010, 05:33:48 pm »
I changed the reaction fire code to get rid of the change in the active team. That way the bug should disappear.
The patch is for trunk r31069.

Can somebody test the patch and report back?

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Reaction Fire - End Turn
« Reply #11 on: August 02, 2010, 10:45:46 am »
that bug was a threading issue and should be fixed with the most recent thread related fixes in trunk - though you are right of course - the activeteam value should not be changed for that. i will have a look at that patch (please post patches to the tracker also - otherwise they tend to get lost)

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Reaction Fire - End Turn
« Reply #12 on: August 02, 2010, 10:57:52 am »