From c990322544269e7fc333506c71c8a39aec08c403 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Mon, 24 Mar 2014 14:59:35 +0100
Subject: wx: Fix memory garbage collector

---
 lib/wx/c_src/wxe_impl.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'lib/wx')

diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index 7d5050e2d0..eeccca1de7 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -418,6 +418,13 @@ void WxeApp::destroyMemEnv(wxeMetaCommand& Ecmd)
   wxWindow *parent = NULL;
   wxeMemEnv * memenv = refmap[Ecmd.port];
 
+  if(!memenv) {
+    wxString msg;
+    msg.Printf(wxT("MemEnv already deleted"));
+    send_msg("debug", &msg);
+    return;
+  }
+
   if(wxe_debug) {
     wxString msg;
     msg.Printf(wxT("Destroying all memory "));
@@ -446,7 +453,6 @@ void WxeApp::destroyMemEnv(wxeMetaCommand& Ecmd)
 	  }
 	  if(recurse_level > 0) {
 	    // Delay delete until we are out of dispatch*
-	    delayed_cleanup->Append(Ecmd.Clone());
 	  } else {
 	    delete win;
 	  }
@@ -455,9 +461,10 @@ void WxeApp::destroyMemEnv(wxeMetaCommand& Ecmd)
     }
   }
 
-  if(recurse_level > 0)
+  if(recurse_level > 0) {
+    delayed_cleanup->Append(Ecmd.Clone());
     return;
-
+  }
   // First pass, delete all top parents/windows of all linked objects
   //   fprintf(stderr, "close port %x\r\n", Ecmd.port);fflush(stderr);
 
-- 
cgit v1.2.3