fix timers: don't clear in snapshot case

Back in August I "fixed" timers running after the board was cleared but
didn't realize that util contexts were shared by snapshot
boards. Clearing those timers when the board's destroyed was stopping
timers for a visible board as well. So I added a boolean indicating
whether to clear timers. Ref counting or similar would be better, but a
lot of work given the concept isn't really in the common/ code at
all (outside of dicts...)
This commit is contained in:
Eric House 2017-02-27 20:20:25 -08:00
parent b849ad4db3
commit 05d583a324
3 changed files with 8 additions and 6 deletions

View file

@ -191,9 +191,11 @@ board_make( MPFORMAL ModelCtxt* model, ServerCtxt* server, DrawCtx* draw,
} /* board_make */
void
board_destroy( BoardCtxt* board )
board_destroy( BoardCtxt* board, XP_Bool ownsUtil )
{
util_clearTimer( board->util, TIMER_TIMERTICK );
if ( ownsUtil ) {
util_clearTimer( board->util, TIMER_TIMERTICK );
}
XP_FREE( board->mpool, board );
} /* board_destroy */
@ -413,7 +415,7 @@ board_drawSnapshot( const BoardCtxt* curBoard, DrawCtx* dctx,
newBoard->showGrid = curBoard->showGrid;
board_draw( newBoard );
board_destroy( newBoard );
board_destroy( newBoard, XP_FALSE );
}
#ifdef COMMON_LAYOUT

View file

@ -68,7 +68,7 @@ void board_setCallbacks( BoardCtxt* board );
void board_setDraw( BoardCtxt* board, DrawCtx* draw );
DrawCtx* board_getDraw( const BoardCtxt* board );
void board_destroy( BoardCtxt* board );
void board_destroy( BoardCtxt* board, XP_Bool ownsUtil );
void board_writeToStream( const BoardCtxt* board, XWStreamCtxt* stream );

View file

@ -363,8 +363,8 @@ void
game_dispose( XWGame* game )
{
/* The board should be reused!!! PENDING(ehouse) */
if ( !!game->board ) {
board_destroy( game->board );
if ( !!game->board ) {
board_destroy( game->board, XP_TRUE );
game->board = NULL;
}