Game Development Community

Incorrect buffer size error in ProjectileData::preload

by Ed Zavada · in Torque Game Engine · 02/16/2007 (9:04 am) · 2 replies

ProjectileData::preload(bool server, char errorBuffer[256]) will print an error message if a shape couldn't be loaded. But the buffer size check is wrong, so that causes an assert.

To fix, change this line:

dSprintf(errorBuffer, sizeof(errorBuffer), "ProjectileData::load: Couldn't load shape \"%s\"", projectileShapeName);

to this:

dSprintf(errorBuffer, 256, "ProjectileData::load: Couldn't load shape \"%s\"", projectileShapeName);

This is needed because sizeof(errorBuffer) returns 4, not 256.

#1
02/16/2007 (10:00 am)
Nice, thank you.
#2
02/16/2007 (11:18 am)
Sadly, the prototype for the function is really the problem... passing "char errorBuffer[255]" is no different than passing "char* errorBuffer" or "char errorBuffer[]".

It should be something like:

typedef char ErrorBufferT[255];

void ProjectileData::preload(bool server, ErrorBufferT& errorBuffer)
{
...
}

then sizeof works as you would expect.