From 881639c2302b1238f79e6e5297d89ab79537ca27 Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 25 Sep 2009 10:17:35 +0000 Subject: [PATCH] fix null ptr exception using null engine. Logic error was not exposed earlier because except in multi-device game the UI would not allow you to ask an engine-less robot player for a hint. --- xwords4/common/board.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index facd6f548..50722c3fe 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1441,28 +1441,30 @@ board_requestHint( BoardCtxt* board, const TrayTileSet* tileSet; ModelCtxt* model = board->model; - result = !!engine && preflight( board ); + if ( !!engine && preflight( board ) ) { - /* undo any current move. otherwise we won't pass the full tray to - the engine. Would it be better, though, to pass the whole tray - regardless where its contents are? */ - if ( model_getCurrentMoveCount( model, selPlayer ) > 0 ) { - model_resetCurrentTurn( model, selPlayer ); - /* Draw's a no-op on Wince with a null hdc, but it'll draw again. - Should probably define OS_INITS_DRAW on Wince...*/ + /* undo any current move. otherwise we won't pass the full tray + to the engine. Would it be better, though, to pass the whole + tray regardless where its contents are? */ + if ( model_getCurrentMoveCount( model, selPlayer ) > 0 ) { + model_resetCurrentTurn( model, selPlayer ); + /* Draw's a no-op on Wince with a null hdc, but it'll draw again. + Should probably define OS_INITS_DRAW on Wince...*/ #ifdef OS_INITS_DRAW - /* On symbian, it's illegal to draw except from inside the Draw - method. But the move search will probably be so fast that it's - ok to wait until we've found the move anyway. */ - redraw = XP_TRUE; + /* On symbian, it's illegal to draw except from inside the + Draw method. But the move search will probably be so fast + that it's ok to wait until we've found the move anyway. */ + redraw = XP_TRUE; #else - board_draw( board ); + board_draw( board ); #endif + } + + tileSet = model_getPlayerTiles( model, selPlayer ); + nTiles = tileSet->nTiles - pti->dividerLoc; + result = nTiles > 0; } - tileSet = model_getPlayerTiles( model, selPlayer ); - nTiles = tileSet->nTiles - pti->dividerLoc; - result = nTiles > 0; if ( result ) { #ifdef XWFEATURE_SEARCHLIMIT BdHintLimits limits;