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
ceSaveAndExit( CEAppGlobals* globals )
{
globals->exiting = XP_TRUE;
(void)ceSaveCurGame( globals, XP_TRUE );
ceSavePrefs( globals );
DestroyWindow(globals->hWnd);
@ -2406,6 +2407,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} else {
/* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */
globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA );
XP_ASSERT( !!globals );
switch (message) {
@ -2738,6 +2740,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
#endif
PostQuitMessage(0);
freeGlobals( globals );
globals = NULL;
SetWindowLongPtr( hWnd, GWL_USERDATA, 0L );
break;
case XWWM_TIME_RQST:
@ -3148,8 +3152,9 @@ ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp,
{
XP_S16 nSent = -1;
CEAppGlobals* globals = (CEAppGlobals*)closure;
CommsAddrRec addr;
LOG_FUNC();
if ( !globals->exiting ) {
CommsAddrRec addr;
XP_ASSERT( !!globals->game.comms );
@ -3164,6 +3169,7 @@ ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp,
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,
@ -3183,7 +3189,8 @@ ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp,
XP_LOGF( "unexpected conType %d", addrp->conType );
XP_ASSERT( 0 );
}
}
}
return nSent;
} /* ce_send_proc */
@ -3752,8 +3759,6 @@ ce_util_addrChange( XW_UtilCtxt* uc,
globals->socketWrap = NULL;
}
}
XP_LOGF( "ce_util_addrChange called; DO SOMETHING." );
} /* ce_util_addrChange */
#endif

View file

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

View file

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