Skip to content

Commit

Permalink
Server|Fixed: Bias surfaces are meaningless, should be ignored
Browse files Browse the repository at this point in the history
The server was crashing when trying to move a plane (e.g., open a door)
because it was trying to access unallocated arrays.
  • Loading branch information
skyjake committed Feb 8, 2013
1 parent 45ec092 commit 8749ece
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 22 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/src/map/bspleaf.cpp
Expand Up @@ -49,10 +49,12 @@ BspLeaf::~BspLeaf()
{
if(bsuf)
{
#ifdef __CLIENT__
for(uint i = 0; i < sector->planeCount; ++i)
{
SB_DestroySurface(bsuf[i]);
}
#endif
Z_Free(bsuf);
}

Expand Down Expand Up @@ -99,6 +101,7 @@ biassurface_t* BspLeaf_BiasSurfaceForGeometryGroup(BspLeaf* leaf, uint groupId)
{
DENG2_ASSERT(leaf);
if(!leaf->sector || groupId > leaf->sector->planeCount) return NULL;
DENG2_ASSERT(leaf->bsuf != 0);
return leaf->bsuf[groupId];
}

Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -50,13 +50,15 @@ HEdge::HEdge(HEdge const &other) : de::MapElement(DMU_HEDGE)

HEdge::~HEdge()
{
#ifdef __CLIENT__
for(uint i = 0; i < 3; ++i)
{
if(bsuf[i])
{
SB_DestroySurface(bsuf[i]);
}
}
#endif
}

coord_t WallDivNode_Height(walldivnode_t* node)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/map/p_data.cpp
Expand Up @@ -147,12 +147,12 @@ DENG_EXTERN_C boolean P_LoadMap(char const* uriCString)
// Init the thinker lists (public and private).
GameMap_InitThinkerLists(map, 0x1 | 0x2);

// Tell shadow bias to initialize the bias light sources.
SB_InitForMap(GameMap_OldUniqueId(map));

GameMap_ClMobjReset(map);

#ifdef __CLIENT__
// Tell shadow bias to initialize the bias light sources.
SB_InitForMap(GameMap_OldUniqueId(map));

// Clear player data, too, since we just lost all clmobjs.
Cl_InitPlayers();

Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/map/p_polyobjs.cpp
Expand Up @@ -45,11 +45,13 @@ void P_PolyobjChanged(Polyobj* po)
HEdge* hedge = line->L_frontside.hedgeLeft;
int i;

#ifdef __CLIENT__
// Shadow bias must be told.
for(i = 0; i < 3; ++i)
{
SB_SurfaceMoved(hedge->bsuf[i]);
}
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -392,6 +392,7 @@ Plane *R_NewPlaneForSector(Sector *sec)
newList[n] = bspLeaf->bsuf[n];
}
Z_Free(bspLeaf->bsuf);
bspLeaf->bsuf = 0;
}

if(!ddMapSetup)
Expand Down Expand Up @@ -463,16 +464,19 @@ void R_DestroyPlaneOfSector(uint id, Sector *sec)
// If this plane's surface is in the glowing list, remove it.
R_SurfaceListRemove(GameMap_GlowingSurfaces(theMap), &plane->surface);

#ifdef __CLIENT__
// Destroy the biassurfaces for this plane.
for(BspLeaf **bspLeafIter = sec->bspLeafs; *bspLeafIter; bspLeafIter++)
{
BspLeaf *bspLeaf = *bspLeafIter;
DENG2_ASSERT(bspLeaf->bsuf != 0);
SB_DestroySurface(bspLeaf->bsuf[id]);
if(id < sec->planeCount)
{
std::memmove(bspLeaf->bsuf + id, bspLeaf->bsuf + id + 1, sizeof(biassurface_t *));
}
}
#endif // __CLIENT__

// Destroy the specified plane.
delete plane;
Expand Down Expand Up @@ -1564,6 +1568,7 @@ boolean R_UpdatePlane(Plane *pln, boolean forceUpdate)
}
}

#ifdef __CLIENT__
// Inform the shadow bias of changed geometry.
if(sec->bspLeafs && *sec->bspLeafs)
{
Expand All @@ -1589,6 +1594,7 @@ boolean R_UpdatePlane(Plane *pln, boolean forceUpdate)
SB_SurfaceMoved(bspLeaf->bsuf[pln->planeID]);
}
}
#endif // __CLIENT__

// We need the decorations updated.
Surface_Update(&pln->surface);
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -424,6 +424,7 @@ void SB_InitForMap(const char* uniqueID)
bsuf->illum = illums;
illums += bsuf->size;

DENG2_ASSERT(leaf->bsuf != 0);
leaf->bsuf[j] = bsuf;
}
}
Expand Down
4 changes: 0 additions & 4 deletions doomsday/server/include/server_dummies.h
Expand Up @@ -151,10 +151,6 @@ DENG_EXTERN_C void Models_Init();
DENG_EXTERN_C void Models_Shutdown();
DENG_EXTERN_C void Models_CacheForState(int stateIndex);

DENG_EXTERN_C void SB_InitForMap(const char* uniqueID);
DENG_EXTERN_C void SB_SurfaceMoved(biassurface_t* bsuf);
DENG_EXTERN_C void SB_DestroySurface(struct biassurface_s* bsuf);

DENG_EXTERN_C void LG_SectorChanged(Sector* sector);

DENG_EXTERN_C void Cl_InitPlayers(void);
Expand Down
15 changes: 0 additions & 15 deletions doomsday/server/src/server_dummies.cpp
Expand Up @@ -597,21 +597,6 @@ void Models_CacheForState(int stateIndex)
DENG_UNUSED(stateIndex);
}

void SB_InitForMap(const char* uniqueID)
{
DENG_UNUSED(uniqueID);
}

void SB_SurfaceMoved(biassurface_t* bsuf)
{
DENG_UNUSED(bsuf);
}

void SB_DestroySurface(struct biassurface_s* bsuf)
{
DENG_UNUSED(bsuf);
};

void LG_SectorChanged(Sector* sector)
{
DENG_UNUSED(sector);
Expand Down

0 comments on commit 8749ece

Please sign in to comment.