Quote:
Originally Posted by Lazy
By dynamically allocating memory you mean by using the lump size instead of the constant value right?
|
Once you load the file header you have all the sizes, but unfortunately they are ignored and the hardcoded
sizes are used instead, which is bad.
Code:
void LoadBSPFile(const char* const filename)
{
dheader_t* header;
LoadFile(filename, (char**)&header);
LoadBSPImage(header);
}
After the LoadFile(filename, (char**)&header);
Your header will have all of the ACTUAL sizes from the BSP file.
These sizes should be used instead of the hard coded ones.
void LoadBSPFile(const char* const filename)
{
dheader_t* header;
LoadFile(filename, (char**)&header);
// alloc memory HERE based on the sizes from the header instead of hard coding them.
// NOW we can safely call LoadBSPImage()
LoadBSPImage(header);
}
So for example, instead of allocating like this:
g_dtexdata = (byte*)AllocBlock(g_max_map_miptex);
do it like this:
g_dtexdata = (byte*)AllocBlock(header->lumps[LUMP_TEXTURES].filelen);
It is the only sure way to know you can read any BSP without crashing.
But it may not be worth the trouble depending on what you are trying to do.
bspFile.cpp needs to be rewritten IMHO.
Cool hack. Thanks for the pic.
Hope this helps...