mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-23 04:52:07 +00:00
Fix stupid bug in brush model indix block size calculations.
We're taking indices and converting them to pointer relative to the hunks base. Yes, that's dirty. Since the indices are stored as 32 bit values and hunks are generally small using 32 bit pointers is enough, even on 64 bit platforms. So the code took the size of void* / 2... See the problem? Yes, that's not a good idea on 32 bit platforms. Bite the bullet and just take the size of void*. Shouldn't be a problem, because the indices are the first thing that's loaded and the hunk is trimmed right after it anyways. If, and just if, we really need each and every byte in the early stages of map loading we need two cases. One for 64 bit and one for 32 bit. This fixes issue #346. Kudos to @ricardosdl for the analysis.
This commit is contained in:
parent
4443d0a2eb
commit
e137ff1168
3 changed files with 26 additions and 8 deletions
|
@ -828,9 +828,15 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
|
|||
dheader_t *header;
|
||||
mmodel_t *bm;
|
||||
|
||||
// map use short indexes that we convert to pointers
|
||||
// pointer size / 2 bytes
|
||||
loadmodel->extradata = Hunk_Begin(modfilelen * sizeof(void*) / 2);
|
||||
/* Because Quake II is is sometimes so ... "optimized" this
|
||||
* is going to be somewhat dirty. The map data contains indices
|
||||
* that we're converting into pointers. Yeah. No comments. The
|
||||
* indices are 32 bit long, they just encode the offset between
|
||||
* the hunks base address and the position in the hunk, so 32 bit
|
||||
* pointers should be enough. But let's play save, waste some
|
||||
* allocations and just take the plattforms pointer size instead
|
||||
* of relying on assumptions. */
|
||||
loadmodel->extradata = Hunk_Begin(modfilelen * sizeof(void*));
|
||||
loadmodel->type = mod_brush;
|
||||
|
||||
if (loadmodel != mod_known)
|
||||
|
|
|
@ -714,9 +714,15 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen)
|
|||
dheader_t *header;
|
||||
mmodel_t *bm;
|
||||
|
||||
// map use short indexes that we convert to pointers
|
||||
// pointer size / 2 bytes
|
||||
loadmodel->extradata = Hunk_Begin(modfilelen * sizeof(void*) / 2);
|
||||
/* Because Quake II is is sometimes so ... "optimized" this
|
||||
* is going to be somewhat dirty. The map data contains indices
|
||||
* that we're converting into pointers. Yeah. No comments. The
|
||||
* indices are 32 bit long, they just encode the offset between
|
||||
* the hunks base address and the position in the hunk, so 32 bit
|
||||
* pointers should be enough. But let's play save, waste some
|
||||
* allocations and just take the plattforms pointer size instead
|
||||
* of relying on assumptions. */
|
||||
loadmodel->extradata = Hunk_Begin(modfilelen * sizeof(void*));
|
||||
loadmodel->type = mod_brush;
|
||||
|
||||
if (loadmodel != mod_known)
|
||||
|
|
|
@ -882,8 +882,14 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
|
|||
dheader_t *header;
|
||||
dmodel_t *bm;
|
||||
|
||||
// map use short indexes that we convert to pointers
|
||||
// pointer size / 2 bytes
|
||||
/* Because Quake II is is sometimes so ... "optimized" this
|
||||
* is going to be somewhat dirty. The map data contains indices
|
||||
* that we're converting into pointers. Yeah. No comments. The
|
||||
* indices are 32 bit long, we're loading the map somewhere at
|
||||
* the lower end of the address space (at least on the common
|
||||
* platforms) so 32 bit pointers should be enough. But let's
|
||||
* play save, waste some memory and just take the plattforms
|
||||
* pointer size instead of relying on assumptions. */
|
||||
loadmodel->extradata = Hunk_Begin(modfilelen * sizeof(void*) / 2);
|
||||
|
||||
loadmodel->type = mod_brush;
|
||||
|
|
Loading…
Reference in a new issue