set flag on exit and don't allocate anything or try to send via

network; clear globals var after freeing it.
This commit is contained in:
ehouse 2009-12-18 04:24:55 +00:00
parent 28265749f9
commit 638337384b
3 changed files with 43 additions and 29 deletions

View file

@ -2052,6 +2052,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
static void static void
ceSaveAndExit( CEAppGlobals* globals ) ceSaveAndExit( CEAppGlobals* globals )
{ {
globals->exiting = XP_TRUE;
(void)ceSaveCurGame( globals, XP_TRUE ); (void)ceSaveCurGame( globals, XP_TRUE );
ceSavePrefs( globals ); ceSavePrefs( globals );
DestroyWindow(globals->hWnd); DestroyWindow(globals->hWnd);
@ -2406,6 +2407,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} else { } else {
/* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */ /* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */
globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA ); globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA );
XP_ASSERT( !!globals );
switch (message) { switch (message) {
@ -2738,6 +2740,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
#endif #endif
PostQuitMessage(0); PostQuitMessage(0);
freeGlobals( globals ); freeGlobals( globals );
globals = NULL;
SetWindowLongPtr( hWnd, GWL_USERDATA, 0L );
break; break;
case XWWM_TIME_RQST: case XWWM_TIME_RQST:
@ -3148,42 +3152,45 @@ ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp,
{ {
XP_S16 nSent = -1; XP_S16 nSent = -1;
CEAppGlobals* globals = (CEAppGlobals*)closure; CEAppGlobals* globals = (CEAppGlobals*)closure;
CommsAddrRec addr;
LOG_FUNC(); LOG_FUNC();
if ( !globals->exiting ) {
CommsAddrRec addr;
XP_ASSERT( !!globals->game.comms ); XP_ASSERT( !!globals->game.comms );
if ( !addrp ) { if ( !addrp ) {
comms_getAddr( globals->game.comms, &addr ); comms_getAddr( globals->game.comms, &addr );
addrp = &addr; addrp = &addr;
}
XP_ASSERT( !!addrp ); /* firing */
switch( addrp->conType ) {
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
case COMMS_CONN_IP_DIRECT:
break;
case COMMS_CONN_RELAY:
if ( !globals->socketWrap ) {
globals->socketWrap = ce_sockwrap_new( MPPARM(globals->mpool)
globals->hWnd,
got_data_proc,
sock_state_change, globals );
} }
nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp ); XP_ASSERT( !!addrp ); /* firing */
break; switch( addrp->conType ) {
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
case COMMS_CONN_IP_DIRECT:
break;
case COMMS_CONN_RELAY:
if ( !globals->exiting ) {
if ( !globals->socketWrap ) {
globals->socketWrap = ce_sockwrap_new( MPPARM(globals->mpool)
globals->hWnd,
got_data_proc,
sock_state_change, globals );
}
nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp );
break;
#endif #endif
#ifdef XWFEATURE_SMS #ifdef XWFEATURE_SMS
case COMMS_CONN_SMS: case COMMS_CONN_SMS:
nSent = ce_sms_send( globals, buf, len, addrp ); nSent = ce_sms_send( globals, buf, len, addrp );
break; break;
#endif #endif
default: default:
XP_LOGF( "unexpected conType %d", addrp->conType ); XP_LOGF( "unexpected conType %d", addrp->conType );
XP_ASSERT( 0 ); XP_ASSERT( 0 );
}
}
} }
return nSent; return nSent;
} /* ce_send_proc */ } /* ce_send_proc */
@ -3752,8 +3759,6 @@ ce_util_addrChange( XW_UtilCtxt* uc,
globals->socketWrap = NULL; globals->socketWrap = NULL;
} }
} }
XP_LOGF( "ce_util_addrChange called; DO SOMETHING." );
} /* ce_util_addrChange */ } /* ce_util_addrChange */
#endif #endif

View file

@ -172,6 +172,7 @@ typedef struct _CEAppGlobals {
XP_Bool penDown; XP_Bool penDown;
XP_Bool hintPending; XP_Bool hintPending;
XP_Bool doGlobalPrefs; XP_Bool doGlobalPrefs;
XP_Bool exiting; /* are we in the process of shutting down? */
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
CommsRelayState relayState; CommsRelayState relayState;

View file

@ -58,6 +58,9 @@ typedef struct _ResStrEntry {
typedef struct _ResStrStorage { typedef struct _ResStrStorage {
ResStrEntry* entries[CE_LAST_RES_ID - CE_FIRST_RES_ID + 1]; ResStrEntry* entries[CE_LAST_RES_ID - CE_FIRST_RES_ID + 1];
#ifdef DEBUG
XP_U16 nUsed;
#endif
} ResStrStorage; } ResStrStorage;
static const ResStrEntry* static const ResStrEntry*
@ -72,6 +75,7 @@ getEntry( CEAppGlobals* globals, XP_U16 resID, XP_Bool isWide )
XP_ASSERT( index < VSIZE(storage->entries) ); XP_ASSERT( index < VSIZE(storage->entries) );
if ( !storage ) { if ( !storage ) {
XP_ASSERT( !globals->exiting );
storage = XP_MALLOC( globals->mpool, sizeof( *storage ) ); storage = XP_MALLOC( globals->mpool, sizeof( *storage ) );
XP_MEMSET( storage, 0, sizeof(*storage) ); XP_MEMSET( storage, 0, sizeof(*storage) );
globals->resStrStorage = storage; globals->resStrStorage = storage;
@ -99,6 +103,9 @@ getEntry( CEAppGlobals* globals, XP_U16 resID, XP_Bool isWide )
} }
storage->entries[index] = entry; storage->entries[index] = entry;
#ifdef DEBUG
++storage->nUsed;
#endif
} }
return entry; return entry;
@ -165,6 +172,7 @@ ceFreeResStrings( CEAppGlobals* globals )
} }
} }
XP_ASSERT( nUsed == storage->nUsed );
XP_FREE( globals->mpool, storage ); XP_FREE( globals->mpool, storage );
globals->resStrStorage = NULL; globals->resStrStorage = NULL;
} }