From d2fda267e5263d05b58d64bcc0788066e79a89a9 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 18 Feb 2011 17:43:01 -0800 Subject: [PATCH] fix assertion failure that happened when I changed whether remote scores were shown mid-game. If the value's not as expected just don't show the score. --- xwords4/common/server.c | 75 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 195594eca..d22be358b 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -809,48 +809,47 @@ postponeRobotMove( ServerCtxt* server ) static void showPrevScore( ServerCtxt* server ) { - XW_UtilCtxt* util = server->vol.util; - XWStreamCtxt* stream; - const XP_UCHAR* str; - CurGameInfo* gi = server->vol.gi; - XP_U16 nPlayers = gi->nPlayers; - XP_U16 prevTurn; - XP_U16 strCode; - LocalPlayer* lp; + if ( server->nv.showRobotScores ) { /* this can be changed between turns */ + XW_UtilCtxt* util = server->vol.util; + XWStreamCtxt* stream; + const XP_UCHAR* str; + CurGameInfo* gi = server->vol.gi; + XP_U16 nPlayers = gi->nPlayers; + XP_U16 prevTurn; + XP_U16 strCode; + LocalPlayer* lp; - XP_ASSERT( server->nv.showRobotScores ); + prevTurn = (server->nv.currentTurn + nPlayers - 1) % nPlayers; + lp = &gi->players[prevTurn]; - prevTurn = (server->nv.currentTurn + nPlayers - 1) % nPlayers; - lp = &gi->players[prevTurn]; + if ( LP_IS_LOCAL(lp) ) { + XP_ASSERT( LP_IS_ROBOT(lp) ); + strCode = STR_ROBOT_MOVED; + } else { + strCode = STR_REMOTE_MOVED; + } - if ( LP_IS_LOCAL(lp) ) { - XP_ASSERT( LP_IS_ROBOT(lp) ); - strCode = STR_ROBOT_MOVED; - } else { - strCode = STR_REMOTE_MOVED; + stream = mkServerStream( server ); + + str = util_getUserString( util, strCode ); + stream_catString( stream, str ); + + if ( !!server->nv.prevMoveStream ) { + XWStreamCtxt* prevStream = server->nv.prevMoveStream; + XP_U16 len = stream_getSize( prevStream ); + XP_UCHAR* buf = XP_MALLOC( server->mpool, len ); + + stream_getBytes( prevStream, buf, len ); + stream_destroy( prevStream ); + server->nv.prevMoveStream = NULL; + + stream_putBytes( stream, buf, len ); + XP_FREE( server->mpool, buf ); + } + + (void)util_userQuery( util, QUERY_ROBOT_MOVE, stream ); + stream_destroy( stream ); } - - stream = mkServerStream( server ); - - str = util_getUserString( util, strCode ); - stream_catString( stream, str ); - - if ( !!server->nv.prevMoveStream ) { - XWStreamCtxt* prevStream = server->nv.prevMoveStream; - XP_U16 len = stream_getSize( prevStream ); - XP_UCHAR* buf = XP_MALLOC( server->mpool, len ); - - stream_getBytes( prevStream, buf, len ); - stream_destroy( prevStream ); - server->nv.prevMoveStream = NULL; - - stream_putBytes( stream, buf, len ); - XP_FREE( server->mpool, buf ); - } - - (void)util_userQuery( util, QUERY_ROBOT_MOVE, stream ); - stream_destroy( stream ); - SETSTATE( server, server->vol.stateAfterShow ); } /* showPrevScore */