FrameAllocator::alloc bug
by William Todd Scott · in Torque Game Engine Advanced · 09/18/2007 (7:59 pm) · 2 replies
Hi,
I there appears to be a bug in the FrameAllocator::alloc function if the FRAMEALLOCATOR_DEBUG_GUARD define is set.
Here is the function:
Notice that the _allocSize variable is never actually used. It is assigned to but not used in the actual allocation.
I'm not sure if the fix is to change the line:
smWaterMark += allocSize;
to
smWaterMark += _allocSize;
Or, if the FRAMEALLOCATOR_DEBUG_GUARD define isn't fully functionaly and should not be used.
Todd
I there appears to be a bug in the FrameAllocator::alloc function if the FRAMEALLOCATOR_DEBUG_GUARD define is set.
Here is the function:
void* FrameAllocator::alloc(const U32 allocSize)
{
U32 _allocSize = allocSize;
#if defined(FRAMEALLOCATOR_DEBUG_GUARD)
_allocSize+=4;
#endif
AssertFatal(smBuffer != NULL, "Error, no buffer!");
AssertFatal(smWaterMark + allocSize <= smHighWaterMark, "Error alloc too large, increase frame size!");
U8* p = &smBuffer[smWaterMark];
smWaterMark += allocSize;
#if defined(TORQUE_DEBUG)
if (smWaterMark > sgMaxFrameAllocation)
sgMaxFrameAllocation = smWaterMark;
#endif
#if defined(FRAMEALLOCATOR_DEBUG_GUARD)
U32 *flag = (U32*) &smBuffer[smWaterMark-4];
*flag = 0xdeadbeef ^ smWaterMark;
#endif
return p;
}Notice that the _allocSize variable is never actually used. It is assigned to but not used in the actual allocation.
I'm not sure if the fix is to change the line:
smWaterMark += allocSize;
to
smWaterMark += _allocSize;
Or, if the FRAMEALLOCATOR_DEBUG_GUARD define isn't fully functionaly and should not be used.
Todd
#2
I was being a bit lazy not tracking down the solution myself, so thanks for the help!
Todd
09/18/2007 (9:55 pm)
Cool.I was being a bit lazy not tracking down the solution myself, so thanks for the help!
Todd
Torque Owner asmaloney (Andy)
Default Studio Name
The fix in TGE is to use _allocSize throughout.
Fixed in the repo - thanks!