From d69903765b1eabb9e92025a096dbdd5e8384dbe5 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 13 Nov 2010 18:59:06 +0000 Subject: [PATCH] Fixed crash after disposing RenderWindow or RenderImage instances, in SFML.Net git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1637 4e206d99-4929-0410-ac5d-dfc041789085 --- bindings/dotnet/src/Graphics/Image.cs | 16 +++++++++++----- bindings/dotnet/src/Graphics/View.cs | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bindings/dotnet/src/Graphics/Image.cs b/bindings/dotnet/src/Graphics/Image.cs index 745395db6..1d16320ea 100644 --- a/bindings/dotnet/src/Graphics/Image.cs +++ b/bindings/dotnet/src/Graphics/Image.cs @@ -374,6 +374,7 @@ namespace SFML internal Image(IntPtr thisPtr) : base(thisPtr) { + myExternal = true; } //////////////////////////////////////////////////////////// @@ -384,15 +385,20 @@ namespace SFML //////////////////////////////////////////////////////////// protected override void Destroy(bool disposing) { - if (!disposing) - Context.Global.SetActive(true); + if (!myExternal) + { + if (!disposing) + Context.Global.SetActive(true); - sfImage_Destroy(This); + sfImage_Destroy(This); - if (!disposing) - Context.Global.SetActive(false); + if (!disposing) + Context.Global.SetActive(false); + } } + bool myExternal = false; + #region Imports [DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] static extern IntPtr sfImage_CreateFromColor(uint Width, uint Height, Color Col); diff --git a/bindings/dotnet/src/Graphics/View.cs b/bindings/dotnet/src/Graphics/View.cs index 77f4147a8..1b7ab5237 100644 --- a/bindings/dotnet/src/Graphics/View.cs +++ b/bindings/dotnet/src/Graphics/View.cs @@ -173,6 +173,7 @@ namespace SFML internal View(IntPtr thisPtr) : base(thisPtr) { + myExternal = true; } //////////////////////////////////////////////////////////// @@ -183,9 +184,11 @@ namespace SFML //////////////////////////////////////////////////////////// protected override void Destroy(bool disposing) { - sfView_Destroy(This); + if (!myExternal) + sfView_Destroy(This); } + private bool myExternal = false; #region Imports [DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] static extern IntPtr sfView_Create();