Skip to content

Commit 68d4db3

Browse files
authored
[GEN][ZH] Fix static initialization order for StatDumpClass and LogClass (#1003)
1 parent eea0e7e commit 68d4db3

File tree

12 files changed

+24
-18
lines changed

12 files changed

+24
-18
lines changed

Generals/Code/GameEngine/Source/Common/Dict.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
160160
Dict::DictPairData* newData = NULL;
161161
if (numPairsNeeded > 0)
162162
{
163+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
163164
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
164165
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
165166
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

Generals/Code/GameEngine/Source/Common/MiniLog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ LogClass::LogClass(const char *fname)
4646
}
4747
pEnd--;
4848
}
49-
AsciiString fullPath;
50-
fullPath.format("%s\\%s", buffer, fname);
51-
m_fp = fopen(fullPath.str(), "wt");
49+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
50+
const std::string fullPath = std::string(buffer) + "\\" + fname;
51+
m_fp = fopen(fullPath.c_str(), "wt");
5252
}
5353

5454
LogClass::~LogClass()

Generals/Code/GameEngine/Source/Common/System/AsciiString.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
138138
return;
139139
}
140140

141+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
141142
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
142143
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
143144
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

Generals/Code/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
9494
return;
9595
}
9696

97+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
9798
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
9899
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
99100
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ LogClass::LogClass(const char *fname)
114114
}
115115
pEnd--;
116116
}
117-
AsciiString fullPath;
118-
fullPath.format("%s\\%s", buffer, fname);
119-
m_fp = fopen(fullPath.str(), "wt");
117+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
118+
const std::string fullPath = std::string(buffer) + "\\" + fname;
119+
m_fp = fopen(fullPath.c_str(), "wt");
120120
}
121121

122122
LogClass::~LogClass()

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ StatDumpClass::StatDumpClass( const char *fname )
162162
}
163163
pEnd--;
164164
}
165-
AsciiString fullPath;
166-
fullPath.format( "%s\\%s", buffer, fname );
167-
m_fp = fopen( fullPath.str(), "wt" );
165+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
166+
const std::string fullPath = std::string(buffer) + "\\" + fname;
167+
m_fp = fopen(fullPath.c_str(), "wt");
168168
}
169169

170170
//=============================================================================

GeneralsMD/Code/GameEngine/Source/Common/Dict.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Dict::DictPair *Dict::ensureUnique(int numPairsNeeded, Bool preserveData, DictPa
160160
Dict::DictPairData* newData = NULL;
161161
if (numPairsNeeded > 0)
162162
{
163+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
163164
DEBUG_ASSERTCRASH(numPairsNeeded <= MAX_LEN, ("Dict::ensureUnique exceeds max pairs length %d with requested length %d", MAX_LEN, numPairsNeeded));
164165
int minBytes = sizeof(Dict::DictPairData) + numPairsNeeded*sizeof(Dict::DictPair);
165166
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ LogClass::LogClass(const char *fname)
4646
}
4747
pEnd--;
4848
}
49-
AsciiString fullPath;
50-
fullPath.format("%s\\%s", buffer, fname);
51-
m_fp = fopen(fullPath.str(), "wt");
49+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
50+
const std::string fullPath = std::string(buffer) + "\\" + fname;
51+
m_fp = fopen(fullPath.c_str(), "wt");
5252
}
5353

5454
LogClass::~LogClass()

GeneralsMD/Code/GameEngine/Source/Common/System/AsciiString.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void AsciiString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveData
138138
return;
139139
}
140140

141+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
141142
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("AsciiString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
142143
int minBytes = sizeof(AsciiStringData) + numCharsNeeded*sizeof(char);
143144
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

GeneralsMD/Code/GameEngine/Source/Common/System/UnicodeString.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void UnicodeString::ensureUniqueBufferOfSize(int numCharsNeeded, Bool preserveDa
9494
return;
9595
}
9696

97+
DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("Cannot use dynamic memory allocator before its initialization. Check static initialization order.\n"));
9798
DEBUG_ASSERTCRASH(numCharsNeeded <= MAX_LEN, ("UnicodeString::ensureUniqueBufferOfSize exceeds max string length %d with requested length %d", MAX_LEN, numCharsNeeded));
9899
int minBytes = sizeof(UnicodeStringData) + numCharsNeeded*sizeof(WideChar);
99100
int actualBytes = TheDynamicMemoryAllocator->getActualAllocationSize(minBytes);

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ LogClass::LogClass(const char *fname)
114114
}
115115
pEnd--;
116116
}
117-
AsciiString fullPath;
118-
fullPath.format("%s\\%s", buffer, fname);
119-
m_fp = fopen(fullPath.str(), "wt");
117+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
118+
const std::string fullPath = std::string(buffer) + "\\" + fname;
119+
m_fp = fopen(fullPath.c_str(), "wt");
120120
}
121121

122122
LogClass::~LogClass()

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ StatDumpClass::StatDumpClass( const char *fname )
163163
}
164164
pEnd--;
165165
}
166-
AsciiString fullPath;
167-
fullPath.format( "%s\\%s", buffer, fname );
168-
m_fp = fopen( fullPath.str(), "wt" );
166+
// TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet.
167+
const std::string fullPath = std::string(buffer) + "\\" + fname;
168+
m_fp = fopen(fullPath.c_str(), "wt");
169169
}
170170

171171
//=============================================================================

0 commit comments

Comments
 (0)