Skip to content

Commit

Permalink
Fixed a logic error which would result in attempting to allocate a se…
Browse files Browse the repository at this point in the history
…ctor->blocks array of size zero.
  • Loading branch information
danij committed Dec 30, 2007
1 parent 4e1612d commit 1c61625
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions doomsday/engine/portable/src/r_lgrid.c
Expand Up @@ -513,19 +513,26 @@ void LG_Init(void)
sector->changedblockcount = changedCount;
sector->blockcount = changedCount + count;

sector->blocks = Z_Malloc(sizeof(unsigned short) * sector->blockcount,
PU_LEVELSTATIC, 0);
for(x = 0, a = 0, b = changedCount; x < lgBlockWidth * lgBlockHeight;
++x)
if(sector->blockcount > 0)
{
if(HasIndexBit(x, 0, indexBitfield))
sector->blocks[a++] = x;
else if(HasIndexBit(x, 0, contributorBitfield))
sector->blocks[b++] = x;
}
sector->blocks = Z_Malloc(sizeof(unsigned short) * sector->blockcount,
PU_LEVELSTATIC, 0);
for(x = 0, a = 0, b = changedCount; x < lgBlockWidth * lgBlockHeight;
++x)
{
if(HasIndexBit(x, 0, indexBitfield))
sector->blocks[a++] = x;
else if(HasIndexBit(x, 0, contributorBitfield))
sector->blocks[b++] = x;
}

assert(a == changedCount);
//assert(b == info->blockcount);
assert(a == changedCount);
//assert(b == info->blockcount);
}
else
{
sector->blocks = NULL;
}
}

M_Free(indexBitfield);
Expand Down

0 comments on commit 1c61625

Please sign in to comment.