Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Common/GameEngine.h"
#include "Common/GameState.h"
#include "Common/GameStateMap.h"
#include "Common/GlobalData.h"
#include "Common/LatchRestore.h"
#include "Common/MapObject.h"
#include "Common/PlayerList.h"
Expand Down Expand Up @@ -563,7 +564,8 @@ SaveCode GameState::saveGame( AsciiString filename, UnicodeString desc,
xferSave.open( filepath );
} catch(...) {
// print error message to the user
TheInGameUI->message( "GUI:Error" );
if (TheGlobalData && !TheGlobalData->m_headless)
TheInGameUI->message( "GUI:Error" );
DEBUG_LOG(( "Error opening file '%s'", filepath.str() ));
return SC_ERROR;
}
Expand Down Expand Up @@ -593,13 +595,16 @@ SaveCode GameState::saveGame( AsciiString filename, UnicodeString desc,
catch( ... )
{

UnicodeString ufilepath;
ufilepath.translate(filepath);
if (TheGlobalData && !TheGlobalData->m_headless)
{
UnicodeString ufilepath;
ufilepath.translate(filepath);

UnicodeString msg;
msg.format( TheGameText->fetch("GUI:ErrorSavingGame"), ufilepath.str() );
UnicodeString msg;
msg.format( TheGameText->fetch("GUI:ErrorSavingGame"), ufilepath.str() );

MessageBoxOk(TheGameText->fetch("GUI:Error"), msg, nullptr);
MessageBoxOk(TheGameText->fetch("GUI:Error"), msg, nullptr);
}

// close the file and get out of here
xferSave.close();
Expand All @@ -611,8 +616,11 @@ SaveCode GameState::saveGame( AsciiString filename, UnicodeString desc,
xferSave.close();

// print message to the user for game successfully saved
UnicodeString msg = TheGameText->fetch( "GUI:GameSaveComplete" );
TheInGameUI->message( msg );
if (TheGlobalData && !TheGlobalData->m_headless)
{
UnicodeString msg = TheGameText->fetch( "GUI:GameSaveComplete" );
TheInGameUI->message( msg );
}

return SC_OK;

Expand Down Expand Up @@ -719,13 +727,16 @@ SaveCode GameState::loadGame( AvailableGameInfo gameInfo )
TheGameEngine->reset();

// print error message to the user
UnicodeString ufilepath;
ufilepath.translate(filepath);
if (TheGlobalData && !TheGlobalData->m_headless)
{
UnicodeString ufilepath;
ufilepath.translate(filepath);

UnicodeString msg;
msg.format( TheGameText->fetch("GUI:ErrorLoadingGame"), ufilepath.str() );
UnicodeString msg;
msg.format( TheGameText->fetch("GUI:ErrorLoadingGame"), ufilepath.str() );

MessageBoxOk(TheGameText->fetch("GUI:Error"), msg, nullptr);
MessageBoxOk(TheGameText->fetch("GUI:Error"), msg, nullptr);
}

return SC_INVALID_DATA; // you can't use a naked "throw" outside of a catch statement!

Expand Down Expand Up @@ -1365,6 +1376,24 @@ void GameState::xferSaveData( Xfer *xfer, SnapshotType which )

DEBUG_LOG(("Looking at block '%s'", blockName.str()));

// Skip blocks with nullptr snapshot (can happen in headless mode)
if( blockInfo->snapshot == nullptr )
{
DEBUG_LOG(("Skipping block '%s' because snapshot is nullptr", blockName.str()));
continue;
}

// Skip visual-only blocks when saving in headless mode
if( TheGlobalData && TheGlobalData->m_headless &&
(blockName.compareNoCase( "CHUNK_TerrainVisual" ) == 0 ||
blockName.compareNoCase( "CHUNK_TacticalView" ) == 0 ||
blockName.compareNoCase( "CHUNK_ParticleSystem" ) == 0 ||
blockName.compareNoCase( "CHUNK_GhostObject" ) == 0) )
{
DEBUG_LOG(("Skipping block '%s' in headless mode", blockName.str()));
continue;
}

//
// for mission save files, we only save the game state block and campaign manager
// because anything else is not needed.
Expand Down Expand Up @@ -1455,6 +1484,15 @@ void GameState::xferSaveData( Xfer *xfer, SnapshotType which )

}

// Skip blocks with nullptr snapshot (can happen in headless mode)
if( blockInfo->snapshot == nullptr )
{
DEBUG_LOG(("Skipping block '%s' because snapshot is nullptr", blockInfo->blockName.str()));
Int dataSize = xfer->beginBlock();
xfer->skip( dataSize );
continue;
}
Comment on lines +1488 to +1494
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Verify the save file is backwards-compatible when visual blocks are omitted in headless saves. The load path handles missing blocks gracefully, but ensure normal-mode loads of headless-created saves work correctly (as noted in the PR TODO).

Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp
Line: 1488:1494

Comment:
**style:** Verify the save file is backwards-compatible when visual blocks are omitted in headless saves. The load path handles missing blocks gracefully, but ensure normal-mode loads of headless-created saves work correctly (as noted in the PR TODO).

How can I resolve this? If you propose a fix, please make it concise.


try
{

Expand Down
Loading