Skip to content

Commit 31e9d97

Browse files
committed
fix: improve stability, memory safety, and macOS compatibility across audio, rendering, and logic systems
1 parent fc0367e commit 31e9d97

17 files changed

Lines changed: 165 additions & 122 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ build.ninja
6565

6666
## Python
6767
__pycache__/
68+
*.py
6869

6970
CRCLogs/
7071

Core/GameEngine/Include/Common/Debug.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ class SimpleProfiler
281281
#define DEBUG_CRASH_MAC(m) ((void)0)
282282
#endif
283283

284-
// #define DEBUG_BUILDMAPCACHE_FLAG
285-
// #define DEBUG_INFO_MAC_FLAG
286-
// #define DEBUG_FILESYSTEM_MAC_FLAG
287-
// #define DEBUG_RENDER_CORE_MAC_FLAG
288-
// #define DEBUG_NETWORK_MAC_FLAG
289-
// #define DEBUG_AUTH_MAC_FLAG
290-
// #define DEBUG_EAC_MAC_FLAG
284+
#define DEBUG_BUILDMAPCACHE_FLAG
285+
#define DEBUG_INFO_MAC_FLAG
286+
#define DEBUG_FILESYSTEM_MAC_FLAG
287+
#define DEBUG_RENDER_CORE_MAC_FLAG
288+
#define DEBUG_NETWORK_MAC_FLAG
289+
#define DEBUG_AUTH_MAC_FLAG
290+
#define DEBUG_EAC_MAC_FLAG
291291

292292
#ifdef DEBUG_BUILDMAPCACHE_FLAG
293293
#define DEBUG_BUILDMAPCACHE(m) MAC_LOG_TAG("DEBUG_BUILDMAPCACHE", m)

Core/GameEngineDevice/Source/VideoDevice/FFmpeg/FFmpegFile.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ Bool FFmpegFile::decodePacket()
257257
}
258258

259259
// Validate the frame before passing to callback
260+
#ifdef __APPLE__
261+
if (stream.frame == nullptr || stream.frame->data[0] == nullptr) {
262+
continue;
263+
}
264+
265+
if (stream.stream_type == AVMEDIA_TYPE_VIDEO && (stream.frame->width <= 0 || stream.frame->height <= 0)) {
266+
continue;
267+
}
268+
269+
if (stream.stream_type == AVMEDIA_TYPE_AUDIO && stream.frame->nb_samples <= 0) {
270+
continue;
271+
}
272+
273+
if (m_frameCallback != nullptr) {
274+
m_frameCallback(stream.frame, stream_idx, stream.stream_type, m_userData);
275+
}
276+
#else
260277
if (stream.frame != nullptr && stream.frame->data[0] != nullptr &&
261278
stream.frame->width > 0 && stream.frame->height > 0) {
262279
if (m_frameCallback != nullptr) {
@@ -265,6 +282,7 @@ Bool FFmpegFile::decodePacket()
265282
} else {
266283
DEBUG_LOG(("Decoded frame has invalid data or dimensions"));
267284
}
285+
#endif
268286
}
269287

270288
return true;

Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ WWINLINE void DX8_ErrorCode(unsigned res)
149149
}
150150

151151
#ifdef __APPLE__
152-
#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
153-
#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
154-
#define DX8CALL_D3D(x) number_of_DX8_calls++;
152+
#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount();
153+
#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; DX8Wrapper::Increment_DX8_CallCount();
154+
#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; DX8Wrapper::Increment_DX8_CallCount();
155155
#define DX8_THREAD_ASSERT() ;
156156
#else // !__APPLE__
157157
#ifdef WWDEBUG

Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ FontCharsClass::Get_Char_Data (WCHAR ch)
12581258
const FontCharsClassCharDataStruct *retval = nullptr;
12591259

12601260
#ifdef __APPLE__
1261-
if ( ch >= 0xFFFD || (ch >= 256 && AlternateUnicodeFont == nullptr && this == AlternateUnicodeFont) )
1261+
if ( ch >= 0xFFFD )
12621262
{
12631263
ch = L'?';
12641264
}
@@ -1397,6 +1397,19 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
13971397
xOrigin = 1;
13981398
}
13991399

1400+
if (GDIBitmapBits == nullptr || MemDC == nullptr) {
1401+
FontCharsClassCharDataStruct *char_data = W3DNEW FontCharsClassCharDataStruct;
1402+
char_data->Value = ch;
1403+
char_data->Width = 0;
1404+
char_data->Buffer = nullptr;
1405+
if ( ch < 256 ) {
1406+
ASCIICharArray[ch] = char_data;
1407+
} else {
1408+
UnicodeCharArray[ch - FirstUnicodeChar] = char_data;
1409+
}
1410+
return char_data;
1411+
}
1412+
14001413
CGContextRef context = (CGContextRef)MemDC;
14011414
CTFontRef ctFont = (CTFontRef)GDIFont;
14021415

@@ -1447,7 +1460,10 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
14471460
int index = (row * stride);
14481461

14491462
for (int col = 0; col < char_size.cx; col ++) {
1450-
uint8 pixel_value = GDIBitmapBits[index];
1463+
uint8 pixel_value = 0;
1464+
if (GDIBitmapBits != nullptr && row < height && col < width && index < stride * height) {
1465+
pixel_value = GDIBitmapBits[index];
1466+
}
14511467
index += 1;
14521468

14531469
uint32 pixel_color = (pixel_value != 0) ? 0x00FFFFFF : 0;
@@ -1566,7 +1582,7 @@ FontCharsClass::Update_Current_Buffer (int char_width)
15661582
// Would we extend past this buffer?
15671583
//
15681584
#ifdef __APPLE__
1569-
int pixels_needed = char_width * CharHeight * 2;
1585+
int pixels_needed = (char_width + PixelOverlap) * CharHeight * 2;
15701586
#else
15711587
int pixels_needed = char_width * CharHeight;
15721588
#endif
@@ -1637,13 +1653,27 @@ FontCharsClass::Create_GDI_Font (const char *font_name)
16371653
CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width, colorSpace, kCGImageAlphaNone);
16381654
CGColorSpaceRelease(colorSpace);
16391655

1656+
if (!context) {
1657+
CFRelease(ctFont);
1658+
GDIFont = nullptr;
1659+
return false;
1660+
}
1661+
16401662
CGContextSetShouldSmoothFonts(context, false);
16411663
CGContextSetAllowsFontSmoothing(context, false);
16421664

16431665
MemDC = (HDC)context;
16441666
GDIBitmapBits = (uint8*)CGBitmapContextGetData(context);
16451667
GDIBitmapStride = CGBitmapContextGetBytesPerRow(context);
16461668

1669+
if (!GDIBitmapBits) {
1670+
CGContextRelease(context);
1671+
MemDC = nullptr;
1672+
CFRelease(ctFont);
1673+
GDIFont = nullptr;
1674+
return false;
1675+
}
1676+
16471677
// Generals font uses compressed width on Windows
16481678
CGAffineTransform matrix = CGAffineTransformIdentity;
16491679
if (doingGenerals) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ W3DShroudLevel W3DShroud::getShroudLevel(Int x, Int y)
259259
{
260260
DEBUG_ASSERTCRASH( m_pSrcTexture != nullptr, ("Reading empty shroud"));
261261

262+
#ifdef __APPLE__
263+
if (x >= 0 && x < m_numCellsX && y >= 0 && y < m_numCellsY)
264+
#else
262265
if (x < m_numCellsX && y < m_numCellsY)
266+
#endif
263267
{
264268
UnsignedShort pixel=*(UnsignedShort *)((Byte *)m_srcTextureData + x*2 + y*m_srcTexturePitch);
265269

@@ -283,7 +287,11 @@ void W3DShroud::setShroudLevel(Int x, Int y, W3DShroudLevel level, Bool textureO
283287
if (!m_pSrcTexture)
284288
return;
285289

290+
#ifdef __APPLE__
291+
if (x >= 0 && x < m_numCellsX && y >= 0 && y < m_numCellsY)
292+
#else
286293
if (x < m_numCellsX && y < m_numCellsY)
294+
#endif
287295
{
288296
if (level < TheGlobalData->m_shroudAlpha)
289297
level = TheGlobalData->m_shroudAlpha;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,9 +1650,6 @@ const WeaponTemplate *WeaponStore::findWeaponTemplate( const AsciiString& name )
16501650
const WeaponTemplate *WeaponStore::findWeaponTemplate( const char* name ) const
16511651
{
16521652
if (stricmp(name, "None") == 0)
1653-
{
1654-
if (stricmp(name, "None") == 0)
1655-
>>>>>>> god-team/main
16561653
return nullptr;
16571654
const WeaponTemplate * wt = findWeaponTemplatePrivate( TheNameKeyGenerator->nameToKey( name ) );
16581655
DEBUG_ASSERTCRASH(wt != nullptr, ("Weapon %s not found!",name));

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void NGMPGame::SyncWithLobby(LobbyEntry& lobby)
121121
}
122122
else // fallback
123123
{
124-
setMap(lobby.map_path.c_str());
124+
setMap(asciiMapCustom);
125125
DEBUG_INFO_MAC(("[SYNC_LOBBY] Map FALLBACK (NOT FOUND): raw='%s' official='%s' custom='%s'", rawMapPath.c_str(), asciiMapOfficial.str(), asciiMapCustom.str()));
126126
}
127127

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ W3DShroudLevel W3DShroud::getShroudLevel(Int x, Int y)
264264
{
265265
DEBUG_ASSERTCRASH( m_pSrcTexture != nullptr, ("Reading empty shroud"));
266266

267+
#ifdef __APPLE__
268+
if (x >= 0 && x < m_numCellsX && y >= 0 && y < m_numCellsY)
269+
#else
267270
if (x < m_numCellsX && y < m_numCellsY)
271+
#endif
268272
{
269273
UnsignedShort pixel=*(UnsignedShort *)((Byte *)m_srcTextureData + x*2 + y*m_srcTexturePitch);
270274

@@ -288,7 +292,11 @@ void W3DShroud::setShroudLevel(Int x, Int y, W3DShroudLevel level, Bool textureO
288292
if (!m_pSrcTexture)
289293
return;
290294

295+
#ifdef __APPLE__
296+
if (x >= 0 && x < m_numCellsX && y >= 0 && y < m_numCellsY)
297+
#else
291298
if (x < m_numCellsX && y < m_numCellsY)
299+
#endif
292300
{
293301
if (level < TheGlobalData->m_shroudAlpha)
294302
level = TheGlobalData->m_shroudAlpha;

Platform/MacOS/Source/Audio/MacOSAudioManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ Bool MacOSAudioManager::isMusicPlaying() const {
582582
}
583583
return FALSE;
584584
}
585-
Bool MacOSAudioManager::isMusicAlreadyLoaded() const { return TRUE; }
586585
Bool MacOSAudioManager::hasMusicTrackCompleted(const AsciiString &trackName, Int numberOfTimes) const { return FALSE; }
587586
AsciiString MacOSAudioManager::getMusicTrackName() const {
588587
for (auto &pa : m_sources) {

0 commit comments

Comments
 (0)