shithub: choc

Download patch

ref: f0c7aa035a81c84e26edd0cd9aafd13f00e0a2fe
parent: 7e59c3bc40bf8c3ffdd5d43978160feb643d71d2
author: Simon Howard <[email protected]>
date: Wed Aug 8 20:04:03 EDT 2007

Don't crash when all players have quit.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 955

--- a/src/am_map.c
+++ b/src/am_map.c
@@ -472,13 +472,21 @@
     m_w = FTOM(f_w);
     m_h = FTOM(f_h);
 
+    plr = &players[0];
+
     // find player to center on initially
     if (!playeringame[pnum = consoleplayer])
+    {
 	for (pnum=0;pnum<MAXPLAYERS;pnum++)
+        {
 	    if (playeringame[pnum])
+            {
+                plr = &players[pnum];
 		break;
-  
-    plr = &players[pnum];
+            }
+        }
+    }
+
     m_x = plr->mo->x - m_w/2;
     m_y = plr->mo->y - m_h/2;
     AM_changeWindowLoc();
--- a/src/d_net.c
+++ b/src/d_net.c
@@ -207,7 +207,6 @@
         }
 
 #endif
-
         netcmds[consoleplayer][maketic % BACKUPTICS] = cmd;
 
 	++maketic;
@@ -408,6 +407,23 @@
 
 }
 
+// Returns true if there are currently any players in the game.
+
+static boolean PlayersInGame(void)
+{
+    int i;
+
+    for (i=0; i<MAXPLAYERS; ++i)
+    {
+        if (playeringame[i])
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 static int GetLowTic(void)
 {
     int i;
@@ -454,7 +470,7 @@
     int realtics;
     int	availabletics;
     int	counts;
-    
+
     // get real tics		
     entertic = I_GetTime() / ticdup;
     realtics = entertic - oldentertics;
@@ -539,7 +555,8 @@
 	counts = 1;
 		
     // wait for new tics if needed
-    while (lowtic < gametic/ticdup + counts)	
+
+    while (!PlayersInGame() || lowtic < gametic/ticdup + counts)	
     {
 	NetUpdate ();   
 
@@ -564,6 +581,14 @@
     {
 	for (i=0 ; i<ticdup ; i++)
 	{
+            // check that there are players in the game.  if not, we cannot
+            // run a tic.
+        
+            if (!PlayersInGame())
+            {
+                return;
+            }
+    
 	    if (gametic/ticdup > lowtic)
 		I_Error ("gametic>lowtic");
 	    if (advancedemo)
@@ -592,3 +617,4 @@
 	NetUpdate ();	// check for new console commands
     }
 }
+