Skip to content

[GEN][ZH] Fix static initialization order for StatDumpClass and LogClass #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Generals/Code/GameEngine/Source/Common/Dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
Dict::DictPairData* newData = NULL;
if (numPairsNeeded > 0)
{
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
7 changes: 4 additions & 3 deletions Generals/Code/GameEngine/Source/Common/MiniLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ LogClass::LogClass(const char *fname)
}
pEnd--;
}
AsciiString fullPath;
fullPath.format("%s\\%s", buffer, fname);
m_fp = fopen(fullPath.str(), "wt");
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

LogClass::~LogClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
return;
}

DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
return;
}

DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ LogClass::LogClass(const char *fname)
}
pEnd--;
}
AsciiString fullPath;
fullPath.format("%s\\%s", buffer, fname);
m_fp = fopen(fullPath.str(), "wt");
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

LogClass::~LogClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ StatDumpClass::StatDumpClass( const char *fname )
}
pEnd--;
}
AsciiString fullPath;
fullPath.format( "%s\\%s", buffer, fname );
m_fp = fopen( fullPath.str(), "wt" );
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

//=============================================================================
Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/Dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
Dict::DictPairData* newData = NULL;
if (numPairsNeeded > 0)
{
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
7 changes: 4 additions & 3 deletions GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ LogClass::LogClass(const char *fname)
}
pEnd--;
}
AsciiString fullPath;
fullPath.format("%s\\%s", buffer, fname);
m_fp = fopen(fullPath.str(), "wt");
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

LogClass::~LogClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
return;
}

DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
return;
}

DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order."));
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ LogClass::LogClass(const char *fname)
}
pEnd--;
}
AsciiString fullPath;
fullPath.format("%s\\%s", buffer, fname);
m_fp = fopen(fullPath.str(), "wt");
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

LogClass::~LogClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ StatDumpClass::StatDumpClass( const char *fname )
}
pEnd--;
}
AsciiString fullPath;
fullPath.format( "%s\\%s", buffer, fname );
m_fp = fopen( fullPath.str(), "wt" );
// TheSuperHackers @bugfix Caball009 03/06/2025 Use std::string instead of AsciiString here to avoid possible static initialization order fiasco
// TheDynamicMemoryAllocator is used by AsciiString and may not have been initialized yet
const std::string fullPath = std::string(buffer) + "\\" + fname;
m_fp = fopen(fullPath.c_str(), "wt");
}

//=============================================================================
Expand Down
Loading