LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0494-wx-Do-not-delay-deletes-of-wxGraphicContext.patch of Package erlang (Project home:Ledest:erlang:20)

From 2634c45c63dc6038ab9c738e9ab8ace490802f6d Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Fri, 16 Nov 2018 09:35:36 +0100
Subject: [PATCH] wx: Do not delay deletes of wxGraphicContext

Fixes crash on Mojave, where refresh events are sent early and
invoked recursively the delete of wxGraphicContext was delayed
until after callback returned causing the crash to happen.
---
 lib/wx/api_gen/wx_gen_cpp.erl  |  9 +++++++--
 lib/wx/c_src/gen/wxe_funcs.cpp | 10 +++++-----
 lib/wx/c_src/wxe_impl.cpp      |  4 ++--
 lib/wx/c_src/wxe_impl.h        |  2 +-
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/wx/api_gen/wx_gen_cpp.erl b/lib/wx/api_gen/wx_gen_cpp.erl
index 573abfa9b8..4261ebe7bc 100644
--- a/lib/wx/api_gen/wx_gen_cpp.erl
+++ b/lib/wx/api_gen/wx_gen_cpp.erl
@@ -995,8 +995,13 @@ build_ret_types(Type,Ps) ->
 	   end,
     lists:foldl(Calc, Free, Ps).
 
-build_ret(Name,_,#type{base={class,Class},single=true}) ->
-    w(" rt.addRef(getRef((void *)~s,memenv), \"~s\");~n",[Name,Class]);
+build_ret(Name,_D,#type{base={class,Class},single=true}=_T) ->
+    case Class of
+        "wxGraphicsContext" ->
+            w(" rt.addRef(getRef((void *)~s,memenv,8), \"~s\");~n",[Name,Class]);
+        _ ->
+            w(" rt.addRef(getRef((void *)~s,memenv), \"~s\");~n",[Name,Class])
+    end;
 build_ret(Name,_,#type{name="wxTreeItemId",single=true}) ->
     w(" rt.add((wxUIntPtr *) ~s.m_pItem);~n",[Name]);
 build_ret(Name,_,#type{name="wxTreeItemIdValue",single=true}) ->
diff --git a/lib/wx/c_src/gen/wxe_funcs.cpp b/lib/wx/c_src/gen/wxe_funcs.cpp
index a47d602337..6e661a206f 100644
--- a/lib/wx/c_src/gen/wxe_funcs.cpp
+++ b/lib/wx/c_src/gen/wxe_funcs.cpp
@@ -6147,18 +6147,18 @@ case wxGraphicsObject_IsNull: { // wxGraphicsObject::IsNull
 case wxGraphicsContext_Create_1_1: { // wxGraphicsContext::Create
  wxWindowDC * dc = (wxWindowDC *) getPtr(bp,memenv); bp += 4;
  wxGraphicsContext * Result = (wxGraphicsContext*)wxGraphicsContext::Create(*dc);
- rt.addRef(getRef((void *)Result,memenv), "wxGraphicsContext");
+ rt.addRef(getRef((void *)Result,memenv,8), "wxGraphicsContext");
  break;
 }
 case wxGraphicsContext_Create_1_0: { // wxGraphicsContext::Create
  wxWindow *window = (wxWindow *) getPtr(bp,memenv); bp += 4;
  wxGraphicsContext * Result = (wxGraphicsContext*)wxGraphicsContext::Create(window);
- rt.addRef(getRef((void *)Result,memenv), "wxGraphicsContext");
+ rt.addRef(getRef((void *)Result,memenv,8), "wxGraphicsContext");
  break;
 }
 case wxGraphicsContext_Create_0: { // wxGraphicsContext::Create
  wxGraphicsContext * Result = (wxGraphicsContext*)wxGraphicsContext::Create();
- rt.addRef(getRef((void *)Result,memenv), "wxGraphicsContext");
+ rt.addRef(getRef((void *)Result,memenv,8), "wxGraphicsContext");
  break;
 }
 case wxGraphicsContext_CreatePen: { // wxGraphicsContext::CreatePen
@@ -6999,7 +6999,7 @@ case wxGraphicsRenderer_CreateContext_1_1: { // wxGraphicsRenderer::CreateContex
  wxWindowDC * dc = (wxWindowDC *) getPtr(bp,memenv); bp += 4;
  if(!This) throw wxe_badarg(0);
  wxGraphicsContext * Result = (wxGraphicsContext*)This->CreateContext(*dc);
- rt.addRef(getRef((void *)Result,memenv), "wxGraphicsContext");
+ rt.addRef(getRef((void *)Result,memenv,8), "wxGraphicsContext");
  break;
 }
 case wxGraphicsRenderer_CreateContext_1_0: { // wxGraphicsRenderer::CreateContext
@@ -7007,7 +7007,7 @@ case wxGraphicsRenderer_CreateContext_1_0: { // wxGraphicsRenderer::CreateContex
  wxWindow *window = (wxWindow *) getPtr(bp,memenv); bp += 4;
  if(!This) throw wxe_badarg(0);
  wxGraphicsContext * Result = (wxGraphicsContext*)This->CreateContext(window);
- rt.addRef(getRef((void *)Result,memenv), "wxGraphicsContext");
+ rt.addRef(getRef((void *)Result,memenv,8), "wxGraphicsContext");
  break;
 }
 
diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index 1510866f09..f856099ffa 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -591,7 +591,7 @@ int WxeApp::newPtr(void * ptr, int type, wxeMemEnv *memenv) {
   return ref;
 }
 
-int WxeApp::getRef(void * ptr, wxeMemEnv *memenv) {
+int WxeApp::getRef(void * ptr, wxeMemEnv *memenv, int type) {
   if(!ptr) return 0;  // NULL and zero is the same
   ptrMap::iterator it = ptr2ref.find(ptr);
   if(it != ptr2ref.end()) {
@@ -618,7 +618,7 @@ int WxeApp::getRef(void * ptr, wxeMemEnv *memenv) {
   }
 
   memenv->ref2ptr[ref] = ptr;
-  ptr2ref[ptr] = new wxeRefData(ref, 0, false, memenv);
+  ptr2ref[ptr] = new wxeRefData(ref, type, false, memenv);
   return ref;
 }
 
diff --git a/lib/wx/c_src/wxe_impl.h b/lib/wx/c_src/wxe_impl.h
index 140a2bd36a..69cc81c429 100644
--- a/lib/wx/c_src/wxe_impl.h
+++ b/lib/wx/c_src/wxe_impl.h
@@ -84,7 +84,7 @@ public:
   wxeMemEnv * getMemEnv(ErlDrvTermData port);
 
   int  newPtr(void * ptr, int type, wxeMemEnv *memenv);
-  int  getRef(void * ptr, wxeMemEnv *memenv);
+  int  getRef(void * ptr, wxeMemEnv *memenv, int type = 0);
   void * getPtr(char * bp, wxeMemEnv *memenv);
   void clearPtr(void *ptr);
   wxeRefData * getRefData(void *ptr);
-- 
2.16.4