Skip to content

Commit eb4363e

Browse files
committed
bugfix(client): Fix crash in WorldBuilder scene
1 parent df6ebbd commit eb4363e

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

Core/GameEngine/Include/Common/GameUtility.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
// For miscellaneous game utility functions.
2222

2323
class Player;
24+
typedef Int PlayerIndex;
2425

2526
namespace rts
2627
{
2728

2829
Bool localPlayerIsObserving();
2930
Player* getObservedOrLocalPlayer(); ///< Get the current observed or local player. Is never null.
31+
Player* getObservedOrLocalPlayer_Safe(); ///< Get the current observed or local player. Is never null, except when the application does not have players.
32+
PlayerIndex getObservedOrLocalPlayerIndex_Safe(); ///< Get the current observed or local player index. Returns 0 when the application does not have players.
3033

3134
void changeLocalPlayer(Player* player); //< Change local player during game
3235
void changeObservedPlayer(Player* player); ///< Change observed player during game

Core/GameEngine/Source/Common/GameUtility.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,44 @@ Bool localPlayerIsObserving()
6262

6363
Player* getObservedOrLocalPlayer()
6464
{
65+
DEBUG_ASSERTCRASH(TheControlBar != NULL, ("TheControlBar is NULL"));
6566
Player* player = TheControlBar->getObservedPlayer();
6667
if (player == NULL)
68+
{
69+
DEBUG_ASSERTCRASH(ThePlayerList != NULL, ("ThePlayerList is NULL"));
6770
player = ThePlayerList->getLocalPlayer();
71+
}
72+
return player;
73+
}
74+
75+
Player* getObservedOrLocalPlayer_Safe()
76+
{
77+
Player* player = NULL;
78+
79+
if (TheControlBar != NULL)
80+
{
81+
player = TheControlBar->getObservedPlayer();
82+
}
83+
84+
if (player == NULL)
85+
{
86+
if (ThePlayerList != NULL)
87+
{
88+
player = ThePlayerList->getLocalPlayer();
89+
}
90+
}
6891
return player;
6992
}
7093

94+
PlayerIndex getObservedOrLocalPlayerIndex_Safe()
95+
{
96+
if (Player* player = getObservedOrLocalPlayer_Safe())
97+
{
98+
return player->getPlayerIndex();
99+
}
100+
return 0;
101+
}
102+
71103
void changeLocalPlayer(Player* player)
72104
{
73105
ThePlayerList->setLocalPlayer(player);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void W3DPropBuffer::drawProps(RenderInfoClass &rinfo)
365365
m_props[i].ss = OBJECTSHROUD_CLEAR;
366366
}
367367
if (m_props[i].ss == OBJECTSHROUD_INVALID) {
368-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
368+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
369369
m_props[i].ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &m_props[i].location);
370370
}
371371
if (m_props[i].ss >= OBJECTSHROUD_SHROUDED) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable
537537
#ifdef DIRTY_CONDITION_FLAGS
538538
StDrawableDirtyStuffLocker lockDirtyStuff;
539539
#endif
540-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
540+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
541541
RefRenderObjListIterator it(&UpdateList);
542542
// loop through all render objects in the list:
543543
for (it.First(&RenderList); !it.Is_Done();)
@@ -1089,7 +1089,7 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )
10891089
m_translucentObjectsCount = 0; //start of new frame so no translucent objects
10901090
m_occludedObjectsCount = 0;
10911091

1092-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
1092+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
10931093

10941094
#define USE_LIGHT_ENV 1
10951095

@@ -1339,7 +1339,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)
13391339
//Assume no player colors are visible and all stencil bits are free for use by shadows.
13401340
TheW3DShadowManager->setStencilShadowMask(0);
13411341

1342-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
1342+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
13431343

13441344
if (m_numPotentialOccludees && m_numPotentialOccluders)
13451345
{
@@ -1533,7 +1533,7 @@ void RTS3DScene::flushOccludedObjects(RenderInfoClass & rinfo)
15331533

15341534
if (m_occludedObjectsCount)
15351535
{
1536-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
1536+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
15371537

15381538
if (DX8Wrapper::Has_Stencil()) //just in case we have shadows, disable them over occluded pixels.
15391539
{
@@ -1603,7 +1603,7 @@ void RTS3DScene::flushTranslucentObjects(RenderInfoClass & rinfo)
16031603

16041604
if (m_translucentObjectsCount)
16051605
{
1606-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
1606+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
16071607

16081608
for (Int i=0; i<m_translucentObjectsCount; i++)
16091609
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ void W3DTreeBuffer::updateTopplingTree(TTree *tree, Real timeScale)
18491849
return;
18501850

18511851
const W3DTreeDrawModuleData* d = m_treeTypes[tree->treeType].m_data;
1852-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
1852+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
18531853
Coord3D pos;
18541854
pos.set(tree->location.X, tree->location.Y, tree->location.Z);
18551855
ObjectShroudStatus ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &pos);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ static void drawablePostDraw( Drawable *draw, void *userData )
980980
return;
981981

982982
Object* obj = draw->getObject();
983-
const Int localPlayerIndex = rts::getObservedOrLocalPlayer()->getPlayerIndex();
983+
const Int localPlayerIndex = rts::getObservedOrLocalPlayerIndex_Safe();
984984
#if ENABLE_CONFIGURABLE_SHROUD
985985
ObjectShroudStatus ss = (!obj || !TheGlobalData->m_shroudOn) ? OBJECTSHROUD_CLEAR : obj->getShroudedStatus(localPlayerIndex);
986986
#else

0 commit comments

Comments
 (0)