diff --git a/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/GLControlWrapper_SlimDX9.cs b/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/GLControlWrapper_SlimDX9.cs index caad882f19..2024796993 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/GLControlWrapper_SlimDX9.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/GLControlWrapper_SlimDX9.cs @@ -46,6 +46,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX public Control Control { get { return this; } } public SwapChain SwapChain; + public Surface SwapChainBB; public void SetVsync(bool state) { diff --git a/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/IGL_SlimDX9.cs b/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/IGL_SlimDX9.cs index b55a61d916..5b99d93605 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/IGL_SlimDX9.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL.SlimDX/IGL_SlimDX9.cs @@ -806,7 +806,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX _CurrentControl = control; //don't dispose this backbuffer reference, even though it's tempting to. //it results in weird flashes of corruption when changing the vsync setting (unproven; it's another similar code sequence that broke it) - dev.SetRenderTarget(0, _CurrentControl.SwapChain.GetBackBuffer(0)); + dev.SetRenderTarget(0, _CurrentControl.SwapChainBB); } public void EndControl(GLControlWrapper_SlimDX9 control) @@ -816,7 +816,8 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX //don't dispose this backbuffer reference, even though it's tempting to. //it results in weird flashes of corruption when changing the vsync setting (unproven; it's another similar code sequence that broke it) - dev.SetRenderTarget(0, dev.GetBackBuffer(0, 0)); + //do we REALLY need this? + //dev.SetRenderTarget(0, dev.GetBackBuffer(0, 0)); _CurrentControl = null; } @@ -863,24 +864,33 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX { //don't dispose this backbuffer reference, even though it's tempting to. //it results in weird flashes of corruption when changing the vsync setting - dev.SetRenderTarget(0, _CurrentControl.SwapChain.GetBackBuffer(0)); + dev.SetRenderTarget(0, _CurrentControl.SwapChainBB); dev.DepthStencilSurface = null; return; } var tw = rt.Opaque as TextureWrapper; //TODO - cache surface level in an RT wrapper - dev.SetRenderTarget(0, tw.Texture.GetSurfaceLevel(0)); + var surf = tw.Texture.GetSurfaceLevel(0); + dev.SetRenderTarget(0, surf); + surf.Dispose(); dev.DepthStencilSurface = null; } + void DestroyControlSwapChain(GLControlWrapper_SlimDX9 control) + { + if (control.SwapChain == null) + return; + control.SwapChainBB.Dispose(); + control.SwapChainBB = null; + control.SwapChain.Dispose(); + control.SwapChain = null; + } + public void RefreshControlSwapChain(GLControlWrapper_SlimDX9 control) { - if (control.SwapChain != null) - { - control.SwapChain.Dispose(); - control.SwapChain = null; - } + DestroyControlSwapChain(control); + ResetHandlers.Remove(control, "SwapChain"); var pp = new PresentParameters @@ -895,7 +905,8 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX }; control.SwapChain = new SwapChain(dev, pp); - ResetHandlers.Add(control, "SwapChain", () => { control.SwapChain.Dispose(); control.SwapChain = null; }, () => RefreshControlSwapChain(control)); + control.SwapChainBB = control.SwapChain.GetBackBuffer(0); + ResetHandlers.Add(control, "SwapChain", () => DestroyControlSwapChain(control), () => RefreshControlSwapChain(control)); } DeviceLostHandler ResetHandlers = new DeviceLostHandler();