Call AddRef() on the device so it doesn't accidentally get released from underneath the caller.
authorSam Lantinga <slouken@libsdl.org>
Sat, 28 Sep 2013 14:07:17 -0700
changeset 776684b154b1ed71
parent 7765 09937804892a
child 7767 0d425d6327d8
Call AddRef() on the device so it doesn't accidentally get released from underneath the caller.
include/SDL_system.h
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/include/SDL_system.h	Sat Sep 28 14:07:14 2013 -0700
     1.2 +++ b/include/SDL_system.h	Sat Sep 28 14:07:17 2013 -0700
     1.3 @@ -49,7 +49,9 @@
     1.4  */
     1.5  extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
     1.6  
     1.7 -/* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer. */
     1.8 +/* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
     1.9 +   Once you are done using the device, you should release it to avoid a resource leak.
    1.10 + */
    1.11  typedef struct IDirect3DDevice9 IDirect3DDevice9;
    1.12  extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
    1.13  
     2.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:07:14 2013 -0700
     2.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:07:17 2013 -0700
     2.3 @@ -1887,13 +1887,19 @@
     2.4  SDL_RenderGetD3D9Device(SDL_Renderer * renderer)
     2.5  {
     2.6  	D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     2.7 +	IDirect3DDevice9 *device;
     2.8  
     2.9  	// Make sure that this is a D3D renderer
    2.10  	if (renderer->DestroyRenderer != D3D_DestroyRenderer) {
    2.11  		SDL_SetError("Renderer is not a D3D renderer");
    2.12  		return NULL;
    2.13  	}
    2.14 -	return data->device;
    2.15 +
    2.16 +	device = data->device;
    2.17 +	if (device) {
    2.18 +		IDirect3DDevice9_AddRef( device );
    2.19 +	}
    2.20 +	return device;
    2.21  }
    2.22  
    2.23  #endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */