- Fixed HLSL memory leak and crash on exit on 32-bit targets. [Ryan Holtz, Bat Country Entertainment]

Word around the campfire is this totally works and stuff. More technically, it eliminates a number of double-frees and also now cleans up the shadow mask PNG and hlsl_options allocations. (nw)
This commit is contained in:
Ryan Holtz 2011-11-18 06:23:04 +00:00
parent cb03f6722d
commit 9063cb221f
2 changed files with 47 additions and 28 deletions

View File

@ -1,6 +1,6 @@
//============================================================
//
// drawd3d.c - Win32 Direct3D HLSL implementation
// d3dhlsl.c - Win32 Direct3D HLSL implementation
//
//============================================================
//
@ -213,6 +213,13 @@ hlsl_info::hlsl_info()
hlsl_info::~hlsl_info()
{
global_free(options);
if(shadow_bitmap != NULL)
{
global_free(shadow_bitmap);
shadow_bitmap = NULL;
}
}
@ -1734,34 +1741,37 @@ void hlsl_info::end()
if(target_in_use[index] != NULL)
{
d3d_texture_info *tex = target_in_use[index];
if(d3d->texlist == tex)
bool found_in_active_list = false;
d3d_texture_info *test_tex = d3d->texlist;
while (test_tex != NULL)
{
d3d->texlist = tex->next;
if(d3d->texlist != NULL)
if(test_tex == tex)
{
d3d->texlist->prev = NULL;
}
}
else
{
if(tex->next != NULL)
{
tex->next->prev = tex->prev;
}
if(tex->prev != NULL)
{
tex->prev->next = tex->next;
found_in_active_list = true;
break;
}
test_tex = test_tex->next;
}
if (tex->d3dfinaltex != NULL)
(*d3dintf->texture.release)(tex->d3dfinaltex);
if (tex->d3dtex != NULL && tex->d3dtex != tex->d3dfinaltex)
(*d3dintf->texture.release)(tex->d3dtex);
if (tex->d3dsurface != NULL)
(*d3dintf->surface.release)(tex->d3dsurface);
global_free(tex);
// only clean up a texture if it won't be cleaned up by drawd3d
if(!found_in_active_list)
{
if (tex->d3dfinaltex != NULL)
{
(*d3dintf->texture.release)(tex->d3dfinaltex);
tex->d3dfinaltex = NULL;
}
if (tex->d3dtex != NULL && tex->d3dtex != tex->d3dfinaltex)
{
(*d3dintf->texture.release)(tex->d3dtex);
tex->d3dtex = NULL;
}
if (tex->d3dsurface != NULL)
{
(*d3dintf->surface.release)(tex->d3dsurface);
}
global_free(tex);
}
}
if (prescaletexture0[index] != NULL)

View File

@ -892,15 +892,15 @@ static int device_create_resources(d3d_info *d3d)
static void device_delete(d3d_info *d3d)
{
// free our effects
d3d->hlsl->delete_resources();
// delete the HLSL interface
global_free(d3d->hlsl);
// free resources
// free our base resources
device_delete_resources(d3d);
// free our effects
d3d->hlsl->delete_resources();
// free the device itself
if (d3d->device != NULL)
(*d3dintf->device.release)(d3d->device);
@ -921,11 +921,20 @@ static void device_delete_resources(d3d_info *d3d)
d3d_texture_info *tex = d3d->texlist;
d3d->texlist = tex->next;
if (tex->d3dfinaltex != NULL)
{
(*d3dintf->texture.release)(tex->d3dfinaltex);
tex->d3dfinaltex = NULL;
}
if (tex->d3dtex != NULL && tex->d3dtex != tex->d3dfinaltex)
{
(*d3dintf->texture.release)(tex->d3dtex);
tex->d3dtex = NULL;
}
if (tex->d3dsurface != NULL)
{
(*d3dintf->surface.release)(tex->d3dsurface);
tex->d3dsurface = NULL;
}
global_free(tex);
}