From 9f22745fa5949fba736a55f8877652f94ae11299 Mon Sep 17 00:00:00 2001 From: OV2 Date: Sun, 10 Apr 2011 16:06:24 +0200 Subject: [PATCH] Win32: fix double cg function unloading --- win32/CDirect3D.cpp | 27 ++++++++++++++++++--------- win32/COpenGL.cpp | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/win32/CDirect3D.cpp b/win32/CDirect3D.cpp index a68d391c..8e3fb10b 100644 --- a/win32/CDirect3D.cpp +++ b/win32/CDirect3D.cpp @@ -305,6 +305,14 @@ void CDirect3D::DeInitialize() DestroyDrawSurface(); SetShader(NULL); + if(cgContext) { + cgDestroyContext(cgContext); + cgContext = NULL; + } + + if(cgAvailable) + cgD3D9SetDevice(NULL); + if(vertexBuffer) { vertexBuffer->Release(); vertexBuffer = NULL; @@ -320,21 +328,14 @@ void CDirect3D::DeInitialize() pD3D = NULL; } - if(cgContext) { - cgDestroyContext(cgContext); - cgContext = NULL; - } - - if(cgAvailable) - cgD3D9SetDevice(NULL); - init_done = false; afterRenderWidth = 0; afterRenderHeight = 0; quadTextureSize = 0; fullscreen = false; filterScale = 0; - unloadCgLibrary(); + if(cgAvailable) + unloadCgLibrary(); cgAvailable = false; } @@ -943,6 +944,10 @@ bool CDirect3D::ResetDevice() //release prior to reset DestroyDrawSurface(); + if(cgAvailable) { + cgD3D9SetDevice(NULL); + } + if(effect) effect->OnLostDevice(); @@ -975,6 +980,10 @@ bool CDirect3D::ResetDevice() if(effect) effect->OnResetDevice(); + if(cgAvailable) { + cgD3D9SetDevice(pDevice); + } + if(GUI.BilinearFilter) { pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); diff --git a/win32/COpenGL.cpp b/win32/COpenGL.cpp index 5700c2bb..57a17c3f 100644 --- a/win32/COpenGL.cpp +++ b/win32/COpenGL.cpp @@ -318,7 +318,8 @@ void COpenGL::DeInitialize() afterRenderHeight = 0; shaderFunctionsLoaded = false; shader_type = OGL_SHADER_NONE; - unloadCgLibrary(); + if(cgAvailable) + unloadCgLibrary(); cgAvailable = false; }