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:
to this:
This is needed because sizeof(errorBuffer) returns 4, not 256.
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.
#2
It should be something like:
typedef char ErrorBufferT[255];
void ProjectileData::preload(bool server, ErrorBufferT& errorBuffer)
{
...
}
then sizeof works as you would expect.
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.
Associate Orion Elenzil
Real Life Plus