From 13288fd750d83e68a02bfbcf9fb21a2e7a18e257 Mon Sep 17 00:00:00 2001 From: Overhaul Date: Sat, 20 Oct 2007 08:40:25 +0000 Subject: [PATCH] Fix memory leaks in strategic pathing git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1536 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- JA2Prototypes.h | 13 +++++++++++++ MainMenuScreen.cpp | 2 +- MessageBoxScreen.cpp | 31 +++++++++++++++++++++---------- MessageBoxScreen.h | 1 + Options Screen.cpp | 8 ++++---- SCREENS.cpp | 8 ++++---- SaveLoadGame.cpp | 15 +++++++++++---- SaveLoadScreen.cpp | 2 +- ja2_2005Express.vcproj | 8 ++++++++ local.h | 8 ++++---- 10 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 JA2Prototypes.h diff --git a/JA2Prototypes.h b/JA2Prototypes.h new file mode 100644 index 00000000..bb7e6d8c --- /dev/null +++ b/JA2Prototypes.h @@ -0,0 +1,13 @@ +#ifndef _JA2PROTOTYPES_H +#define _JA2PROTOTYPES_H + +/* + * This header does not define any structures. It simply provides a way for all code that only needs a pointer + * reference to structures, to have it without getting locked into mutual includes and other + * hard-to-trace-and-fix behavior. More class and struct defs can be added as necessary. + */ + +class SOLDIERTYPE; +struct AnimationSurfaceType; + +#endif diff --git a/MainMenuScreen.cpp b/MainMenuScreen.cpp index d77d97d2..29be9704 100644 --- a/MainMenuScreen.cpp +++ b/MainMenuScreen.cpp @@ -555,7 +555,7 @@ BOOLEAN CreateDestroyMainMenuButtons( BOOLEAN fCreate ) INT32 cnt; SGPFILENAME filename; INT16 sSlot; - INT32 iStartLoc=0; + //INT32 iStartLoc=0; #ifndef _DEBUG CHAR16 zText[512]; #endif diff --git a/MessageBoxScreen.cpp b/MessageBoxScreen.cpp index f62552ec..efb40122 100644 --- a/MessageBoxScreen.cpp +++ b/MessageBoxScreen.cpp @@ -629,11 +629,17 @@ INT32 DoMessageBox( UINT8 ubStyle, const STR16 zString, UINT32 uiExitScreen, UIN } - InterruptTime(); - PauseGame(); - LockPauseState( 1 ); - // Pause timers as well.... - PauseTime( TRUE ); +#if 0 + gMsgBox.fWasPaused = GamePaused(); + if (!gMsgBox.fWasPaused) + { + InterruptTime(); + PauseGame(); + LockPauseState( 1 ); + // Pause timers as well.... + PauseTime( TRUE ); + } +#endif // Save mouse restriction region... GetRestrictedClipCursor( &gOldCursorLimitRectangle ); @@ -867,11 +873,16 @@ UINT32 ExitMsgBox( INT8 ubExitCode ) // Delete button images UnloadButtonImage( gMsgBox.iButtonImages ); - // Unpause game.... - UnLockPauseState(); - UnPauseGame(); - // UnPause timers as well.... - PauseTime( FALSE ); +#if 0 + if (!gMsgBox.fWasPaused) + { + // Unpause game.... + UnLockPauseState(); + UnPauseGame(); + // UnPause timers as well.... + PauseTime( FALSE ); + } +#endif // Restore mouse restriction region... RestrictMouseCursor( &gOldCursorLimitRectangle ); diff --git a/MessageBoxScreen.h b/MessageBoxScreen.h index a0abaab8..c8f68cf7 100644 --- a/MessageBoxScreen.h +++ b/MessageBoxScreen.h @@ -71,6 +71,7 @@ typedef struct INT8 bHandled; INT32 iBoxId; + BOOLEAN fWasPaused; } MESSAGE_BOX_STRUCT; diff --git a/Options Screen.cpp b/Options Screen.cpp index 78d4f238..57b25ea3 100644 --- a/Options Screen.cpp +++ b/Options Screen.cpp @@ -470,7 +470,7 @@ Uncomment this to enable the check for files to activate the blood and gore opti if( usTextWidth > OPT_TOGGLE_BOX_TEXT_WIDTH ) { //Get how many lines will be used to display the string, without displaying the string - UINT8 ubNumLines = DisplayWrappedString( 0, 0, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, OPT_HIGHLIGHT_COLOR, zOptionsToggleText[ cnt ], FONT_MCOLOR_BLACK, TRUE, LEFT_JUSTIFIED | DONT_DISPLAY_TEXT ) / GetFontHeight( OPT_MAIN_FONT ); + UINT8 ubNumLines = (UINT8) ( DisplayWrappedString( 0, 0, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, OPT_HIGHLIGHT_COLOR, zOptionsToggleText[ cnt ], FONT_MCOLOR_BLACK, TRUE, LEFT_JUSTIFIED | DONT_DISPLAY_TEXT ) / GetFontHeight( OPT_MAIN_FONT ) ); usTextWidth = OPT_TOGGLE_BOX_TEXT_WIDTH; @@ -518,7 +518,7 @@ Uncomment this to enable the check for files to activate the blood and gore opti if( usTextWidth > OPT_TOGGLE_BOX_TEXT_WIDTH ) { //Get how many lines will be used to display the string, without displaying the string - UINT8 ubNumLines = DisplayWrappedString( 0, 0, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, OPT_HIGHLIGHT_COLOR, zOptionsToggleText[ cnt ], FONT_MCOLOR_BLACK, TRUE, LEFT_JUSTIFIED | DONT_DISPLAY_TEXT ) / GetFontHeight( OPT_MAIN_FONT ); + UINT8 ubNumLines = (UINT8) ( DisplayWrappedString( 0, 0, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, OPT_HIGHLIGHT_COLOR, zOptionsToggleText[ cnt ], FONT_MCOLOR_BLACK, TRUE, LEFT_JUSTIFIED | DONT_DISPLAY_TEXT ) / GetFontHeight( OPT_MAIN_FONT ) ); usTextWidth = OPT_TOGGLE_BOX_TEXT_WIDTH; @@ -1052,7 +1052,7 @@ void BtnOptionsTogglesCallback( GUI_BUTTON *btn, INT32 reason ) void HandleOptionToggle( UINT8 ubButton, BOOLEAN fState, BOOLEAN fDown, BOOLEAN fPlaySound ) { static UINT32 uiOptionToggleSound = NO_SAMPLE; - UINT32 uiSideToPlaySoundOn = MIDDLEPAN; + //UINT32 uiSideToPlaySoundOn = MIDDLEPAN; // static BOOLEAN fCheckBoxDrawnDownLastTime = FALSE; if( fState ) @@ -1218,7 +1218,7 @@ void HandleSliderBarMovementSounds() { static UINT32 uiLastSoundFxTime=0; static UINT32 uiLastSpeechTime=0; - UINT32 uiCurTime = GetJA2Clock(); + //UINT32 uiCurTime = GetJA2Clock(); static UINT32 uiLastPlayingSoundID = NO_SAMPLE; static UINT32 uiLastPlayingSpeechID = NO_SAMPLE; diff --git a/SCREENS.cpp b/SCREENS.cpp index faa7d211..b51c52c0 100644 --- a/SCREENS.cpp +++ b/SCREENS.cpp @@ -19,11 +19,11 @@ int iScreenMode = 0; /* 0 for Fullscreen */ #endif BOOL bScreenModeCmdLine = FALSE; -int SCREEN_WIDTH; -int SCREEN_HEIGHT; +UINT16 SCREEN_WIDTH; +UINT16 SCREEN_HEIGHT; -int iScreenWidthOffset; -int iScreenHeightOffset; +INT16 iScreenWidthOffset; +INT16 iScreenHeightOffset; BOOLEAN fDisplayOverheadMap; diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index 2b941c54..4d03a0af 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -513,7 +513,7 @@ BOOLEAN SaveGame( UINT8 ubSaveGameID, STR16 pGameDesc ) HWFILE hFile=0; SAVED_GAME_HEADER SaveGameHeader; CHAR8 zSaveGameName[ MAX_PATH ]; - UINT32 uiSizeOfGeneralInfo = sizeof( GENERAL_SAVE_INFO ); + //UINT32 uiSizeOfGeneralInfo = sizeof( GENERAL_SAVE_INFO ); //UINT8 saveDir[100]; BOOLEAN fPausedStateBeforeSaving = gfGamePaused; BOOLEAN fLockPauseStateBeforeSaving = gfLockPauseState; @@ -1454,7 +1454,7 @@ BOOLEAN LoadSavedGame( UINT8 ubSavedGameID ) INT16 sLoadSectorY; INT8 bLoadSectorZ; CHAR8 zSaveGameName[ MAX_PATH ]; - UINT32 uiSizeOfGeneralInfo = sizeof( GENERAL_SAVE_INFO ); + //UINT32 uiSizeOfGeneralInfo = sizeof( GENERAL_SAVE_INFO ); UINT32 uiRelStartPerc; UINT32 uiRelEndPerc; @@ -3594,7 +3594,7 @@ BOOLEAN SaveEmailToSavedGame( HWFILE hFile ) UINT32 uiNumOfEmails=0; UINT32 uiSizeOfEmails=0; EmailPtr pEmail = pEmailList; - EmailPtr pTempEmail = NULL; + //EmailPtr pTempEmail = NULL; UINT32 cnt; UINT32 uiStringLength=0; UINT32 uiNumBytesWritten=0; @@ -4281,7 +4281,11 @@ BOOLEAN LoadMercPathToSoldierStruct( HWFILE hFile, UINT8 ubID ) //Allocate memory for the new node pTemp = (PathStPtr) MemAlloc( sizeof( PathSt ) ); if( pTemp == NULL ) + { + pTempPath = MoveToBeginningOfPathList( pTempPath ); + ClearStrategicPathList( pTempPath, -1 ); return( FALSE ); + } memset( pTemp, 0 , sizeof( PathSt ) ); @@ -4289,6 +4293,9 @@ BOOLEAN LoadMercPathToSoldierStruct( HWFILE hFile, UINT8 ubID ) FileRead( hFile, pTemp, sizeof( PathSt ), &uiNumBytesRead ); if( uiNumBytesRead != sizeof( PathSt ) ) { + MemFree( pTemp); + pTempPath = MoveToBeginningOfPathList( pTempPath ); + ClearStrategicPathList( pTempPath, -1 ); return(FALSE); } @@ -5109,7 +5116,7 @@ void GetBestPossibleSectorXYZValues( INT16 *psSectorX, INT16 *psSectorY, INT8 *p INT16 sSoldierCnt; SOLDIERTYPE *pSoldier; INT16 bLastTeamID; - INT8 bCount=0; + //INT8 bCount=0; BOOLEAN fFoundAMerc=FALSE; // Set locator to first merc diff --git a/SaveLoadScreen.cpp b/SaveLoadScreen.cpp index dc62d8c9..bb6e7e5a 100644 --- a/SaveLoadScreen.cpp +++ b/SaveLoadScreen.cpp @@ -1813,7 +1813,7 @@ void SelectedSaveRegionMovementCallBack(MOUSE_REGION * pRegion, INT32 reason ) void InitSaveLoadScreenTextInputBoxes() { - UINT32 uiStartLoc=0; + //UINT32 uiStartLoc=0; UINT16 usPosY; SAVED_GAME_HEADER SaveGameHeader; diff --git a/ja2_2005Express.vcproj b/ja2_2005Express.vcproj index 3f2949ec..3ef1a487 100644 --- a/ja2_2005Express.vcproj +++ b/ja2_2005Express.vcproj @@ -255,6 +255,10 @@ RelativePath=".\Options Screen.cpp" > + + @@ -377,6 +381,10 @@ RelativePath=".\Options Screen.h" > + + diff --git a/local.h b/local.h index d92dc5f4..35c27896 100644 --- a/local.h +++ b/local.h @@ -25,12 +25,12 @@ #define WINDOWED_MODE #endif -extern int SCREEN_WIDTH; -extern int SCREEN_HEIGHT; +extern UINT16 SCREEN_WIDTH; +extern UINT16 SCREEN_HEIGHT; extern int iResolution; // Resolution id from the ini file -extern int iScreenWidthOffset; -extern int iScreenHeightOffset; +extern INT16 iScreenWidthOffset; +extern INT16 iScreenHeightOffset; extern BOOLEAN fDisplayOverheadMap;