Skip to content

Commit

Permalink
Fix crashes when world is null after connect spam
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Dec 13, 2024
1 parent d7d3742 commit 070d498
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/bzflag/BackgroundRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "MainWindow.h"
#include "SceneNode.h"
#include "effectsRenderer.h"
#include "World.h"

static const GLfloat squareShape[4][2] =
{
Expand Down Expand Up @@ -664,7 +665,8 @@ void BackgroundRenderer::renderGroundEffects(SceneRenderer& renderer,

if (!blank)
{
if (doShadows && shadowsVisible && !drawingMirror)
const World *_world = World::getWorld();
if (doShadows && shadowsVisible && !drawingMirror && _world)
drawGroundShadows(renderer);

// draw light receivers on ground (little meshes under light sources so
Expand Down
11 changes: 7 additions & 4 deletions src/bzflag/SceneRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,18 @@ void SceneRenderer::renderScene(bool UNUSED(_lastFrame), bool UNUSED(_sameFrame)
int i;
const bool lightLists = BZDB.isTrue("lightLists");

const World* world = World::getWorld();


// avoid OpenGL calls as long as possible -- there's a good
// chance we're waiting on the vertical retrace.

// get a list of the dynamic lights
getLights();

// get the obstacle sceneNodes and shadowNodes
getRenderNodes();
if (world)
getRenderNodes();

// prepare transforms
// note -- lights should not be positioned before view is set
Expand Down Expand Up @@ -1000,17 +1004,16 @@ void SceneRenderer::renderScene(bool UNUSED(_lastFrame), bool UNUSED(_sameFrame)
if (useHiddenLineOn)
glEnable(GL_POLYGON_OFFSET_FILL);


///////////////////////
// THE BIG RENDERING //
///////////////////////
doRender();
if (world)
doRender();


if (scene && BZDBCache::showCullingGrid)
scene->drawCuller();

const World* world = World::getWorld();
if (scene && BZDBCache::showCollisionGrid && (world != NULL))
world->drawCollisionGrid();

Expand Down
19 changes: 13 additions & 6 deletions src/bzflag/playing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,7 @@ static void handleServerMessage(bool human, uint16_t code,
{
bool checkScores = false;
static WordFilter *wordfilter = (WordFilter *)BZDB.getPointer("filter");
const World *_world = World::getWorld();

switch (code)
{
Expand Down Expand Up @@ -2340,7 +2341,10 @@ static void handleServerMessage(bool human, uint16_t code,
for (int i = 0; i < numTeams; i++)
{
msg = nboUnpackUShort(msg, team);
msg = teams[int(team)].unpack(msg);
Team uTeam;
msg = uTeam.unpack(msg);
if (_world)
teams[int(team)] = uTeam;
}
checkScores = true;
break;
Expand Down Expand Up @@ -5745,16 +5749,18 @@ static void drawUI()
hud->setFrameRadarTriangleCount(0);
}

const World *_world = World::getWorld();

// update the HUD (player list, alerts)
if (World::getWorld() && hud)
if (_world && hud)
hud->render(*sceneRenderer);

// draw the control panel
if (controlPanel)
controlPanel->render(*sceneRenderer);

// draw the radar
if (radar)
if (radar && _world)
{
const bool showBlankRadar = !myTank || (myTank && myTank->isPaused());
const bool observer = myTank && (myTank->getTeam() == ObserverTeam);
Expand Down Expand Up @@ -6124,7 +6130,8 @@ void drawFrame(const float dt)

// add dynamic nodes
SceneDatabase* scene = sceneRenderer->getSceneDatabase();
if (scene && myTank && world)
World *_world = World::getWorld();
if (scene && myTank && _world)
{

int i;
Expand Down Expand Up @@ -7324,7 +7331,7 @@ static void playingLoop()
}

// do motion
if (myTank && world)
if (myTank && _world)
{
if (myTank->isAlive() && !myTank->isPaused())
{
Expand Down Expand Up @@ -7374,7 +7381,7 @@ static void playingLoop()
#endif

// adjust properties based on flags (dimensions, cloaking, etc...)
if (myTank)
if (myTank && _world)
myTank->updateTank(dt, true);
for (i = 0; i < curMaxPlayers; i++)
{
Expand Down

0 comments on commit 070d498

Please sign in to comment.