mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
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:
parent
28265749f9
commit
638337384b
3 changed files with 43 additions and 29 deletions
|
@ -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,42 +3152,45 @@ 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 );
|
||||
XP_ASSERT( !!globals->game.comms );
|
||||
|
||||
if ( !addrp ) {
|
||||
comms_getAddr( globals->game.comms, &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 );
|
||||
if ( !addrp ) {
|
||||
comms_getAddr( globals->game.comms, &addr );
|
||||
addrp = &addr;
|
||||
}
|
||||
|
||||
nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp );
|
||||
break;
|
||||
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->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
|
||||
#ifdef XWFEATURE_SMS
|
||||
case COMMS_CONN_SMS:
|
||||
nSent = ce_sms_send( globals, buf, len, addrp );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
nSent = ce_sms_send( globals, buf, len, addrp );
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
XP_LOGF( "unexpected conType %d", addrp->conType );
|
||||
XP_ASSERT( 0 );
|
||||
default:
|
||||
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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue