Double-free emergency fix for virtual resources

- vres_GetMap guarantees the same memory for the same lump id, provided it's active
- vres_Free won't delete curmapvirt unless you do some silly temp pointer stuff
This commit is contained in:
toaster 2023-07-24 23:40:30 +01:00
parent 87aab3c881
commit b4197a2263
3 changed files with 22 additions and 2 deletions

View file

@ -8280,8 +8280,15 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
}
// Now safe to free.
vres_Free(curmapvirt);
curmapvirt = NULL;
// We do the following silly
// construction because vres_Free
// no-sells deletions of pointers
// that are == curmapvirt.
{
virtres_t *temp = curmapvirt;
curmapvirt = NULL;
vres_Free(temp);
}
if (!reloadinggamestate)
{

View file

@ -35,6 +35,7 @@ extern boolean levelloading;
extern UINT8 levelfadecol;
extern lumpnum_t lastloadedmaplumpnum; // for comparative savegame
extern virtres_t *curmapvirt;
/* for levelflat type */
enum

View file

@ -2354,6 +2354,12 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
virtlump_t* vlumps = NULL;
size_t numlumps = 0;
if (lastloadedmaplumpnum == lumpnum && curmapvirt != NULL)
{
// Avoid duplicating all our hard work.
return curmapvirt;
}
if (W_IsLumpWad(lumpnum))
{
UINT32 realentry;
@ -2430,6 +2436,12 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
*/
void vres_Free(virtres_t* vres)
{
if (vres == curmapvirt)
{
// No-sell multiple references.
return;
}
while (vres->numlumps--)
{
if (vres->vlumps[vres->numlumps].data)