project-navigation
Personal tools

Author Topic: Patch for possible divide by zero error  (Read 2378 times)

ubequitz

  • Guest
Patch for possible divide by zero error
« on: August 30, 2006, 03:57:15 am »
Have been playing the Japan map quite a bit. On one retry got this:
Code: [Select]
New morale is 159 - entity morale is 159
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!
Can't perform action - not enough TUs!

Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 46912514634240 (LWP 1770)]
0x00002aaac4d36c52 in AI_CivilianCalcGuete (ent=0x15ea8ab0, to=0x7fffff86c670 "w\201", aia=0x7fffff86c6a0) at game/g_ai.c:290
290             guete += GUETE_CIV_LAZINESS * tu / ent->TU;
(gdb) bt
#0  0x00002aaac4d36c52 in AI_CivilianCalcGuete (ent=0x15ea8ab0, to=0x7fffff86c670 "w\201", aia=0x7fffff86c6a0) at game/g_ai.c:290
#1  0x00002aaac4d36e4d in AI_ActorThink (player=0x156d0de0, ent=0x15ea8ab0) at game/g_ai.c:351
#2  0x00002aaac4d3c037 in G_MoralePanic (ent=0x15ea8ab0, sanity=qfalse) at game/g_client.c:1370
#3  0x00002aaac4d3c4aa in G_MoraleBehaviour (team=1) at game/g_client.c:1446
#4  0x00002aaac4d40859 in G_ClientEndRound (player=0x156d1fe0) at game/g_client.c:2511
#5  0x00002aaac4d371b7 in AI_Run () at game/g_ai.c:415
#6  0x00002aaac4d42ceb in G_RunFrame () at game/g_main.c:547
#7  0x0000000000461383 in SV_RunGameFrame () at server/sv_main.c:629
#8  0x000000000046149f in SV_Frame (msec=18) at server/sv_main.c:676
#9  0x000000000045452a in Qcommon_Frame (msec=18) at qcommon/common.c:1535
#10 0x000000000046df2e in main (argc=10, argv=0x7fffff86c9b8) at ports/linux/sys_linux.c:421


Looking through the code I can only think the Arithmetic exception was casued by a divide by zero. The following patch ensures this won't happen again:
Code: [Select]

Index: src/game/g_ai.c
===================================================================
--- src/game/g_ai.c     (revision 3093)
+++ src/game/g_ai.c     (working copy)
@@ -287,7 +287,8 @@
        guete += GUETE_RUN_AWAY * minDist / RUN_AWAY_DIST;

        /* add laziness */
-       guete += GUETE_CIV_LAZINESS * tu / ent->TU;
+        if (ent->TU > 0)
+               guete += GUETE_CIV_LAZINESS * tu / ent->TU;

        /* add random effects */
        guete += GUETE_CIV_RANDOM * frand();