From db8125271b4d600c89732d6abbf530640c8c75c8 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 19 Jul 2006 02:55:08 +0000 Subject: [PATCH] I hate adding random booleans, but it is an easy mistake to miss a case where turnDidStart() results in an immediate call to endTurn() and things then spiral off into infinite loop land. If someone genuinely does want to end a turn mmediately in turnDidStart() they can queue up a dobj unit to do so. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@27 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../turn/server/TurnGameManagerDelegate.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java index b6c95dec..31dbef3a 100644 --- a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java @@ -144,7 +144,17 @@ public class TurnGameManagerDelegate extends GameManagerDelegate // and start the next turn if desired if (_turnIdx != -1) { - startTurn(); + // prevent infinite loops if the game manager decides to + // unwittingly call endTurn() in turnDidStart() + if (_startingTurn) { + Log.warning("Refusing to start looping in endTurn() " + + "[game=" + where() + "]."); + Thread.dumpStack(); + } else { + _startingTurn = true; + startTurn(); + } + _startingTurn = false; } else { // otherwise, clear out the turn holder @@ -243,4 +253,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate /** The player index of the current turn holder or -1 if * it's no one's turn. */ protected int _turnIdx = -1; + + /** Used to avoid infinite loops in buggy game managers that call endTurn() + * from startTurn(). */ + protected boolean _startingTurn; }