Skip to content

Commit

Permalink
Fixed|libdoomsday|DED: Discarding definitions while parsing
Browse files Browse the repository at this point in the history
The "dummy" instances were not being released as the new design
requires.
  • Loading branch information
skyjake committed Jul 22, 2014
1 parent 4c3824d commit 515ee11
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions doomsday/libdoomsday/src/defs/dedparser.cpp
Expand Up @@ -130,6 +130,14 @@ using namespace de;

static struct xgclass_s *xgClassLinks;

// Helper for managing a dummy definition allocated on the stack.
template <typename T>
struct Dummy : public T {
Dummy() { zap(*this); }
~Dummy() { T::release(); }
void clear() { T::release(); zap(*this); }
};

void DED_SetXGClassLinks(struct xgclass_s *links)
{
xgClassLinks = links;
Expand Down Expand Up @@ -914,7 +922,8 @@ DENG2_PIMPL(DEDParser)
if(ISTOKEN("Mobj") || ISTOKEN("Thing"))
{
dd_bool bModify = false;
ded_mobj_t* mo, dummyMo;
ded_mobj_t* mo;
Dummy<ded_mobj_t> dummyMo;

ReadToken();
if(!ISTOKEN("Mods"))
Expand All @@ -938,7 +947,7 @@ DENG2_PIMPL(DEDParser)
<< (source? source->lineNumber : 0);

// We'll read into a dummy definition.
memset(&dummyMo, 0, sizeof(dummyMo));
dummyMo.clear();
mo = &dummyMo;
}
else
Expand Down Expand Up @@ -1014,7 +1023,8 @@ DENG2_PIMPL(DEDParser)
if(ISTOKEN("State"))
{
dd_bool bModify = false;
ded_state_t* st, dummyState;
ded_state_t* st;
Dummy<ded_state_t> dummyState;

ReadToken();
if(!ISTOKEN("Mods"))
Expand All @@ -1038,7 +1048,7 @@ DENG2_PIMPL(DEDParser)
<< (source? source->lineNumber : 0);

// We'll read into a dummy definition.
memset(&dummyState, 0, sizeof(dummyState));
dummyState.clear();
st = &dummyState;
}
else
Expand Down Expand Up @@ -1179,7 +1189,8 @@ DENG2_PIMPL(DEDParser)
if(ISTOKEN("Material"))
{
bool bModify = false;
ded_material_t *mat, dummyMat;
ded_material_t *mat;
Dummy<ded_material_t> dummyMat;

ReadToken();
if(!ISTOKEN("Mods"))
Expand All @@ -1206,7 +1217,7 @@ DENG2_PIMPL(DEDParser)

// We'll read into a dummy definition.
idx = -1;
memset(&dummyMat, 0, sizeof(dummyMat));
dummyMat.clear();
mat = &dummyMat;
}
else
Expand Down

0 comments on commit 515ee11

Please sign in to comment.