From 25c00c82ba2b0c36b908073a12fc37203c19c516 Mon Sep 17 00:00:00 2001 From: Ye Kuang Date: Mon, 18 May 2020 21:50:16 +0900 Subject: [PATCH 1/2] [Mac] [GUI] Fix bug due to View class name conflict --- taichi/gui/cocoa.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/taichi/gui/cocoa.cpp b/taichi/gui/cocoa.cpp index 8f620113fd4e4..584399b66a578 100644 --- a/taichi/gui/cocoa.cpp +++ b/taichi/gui/cocoa.cpp @@ -1,16 +1,16 @@ -#include "taichi/util/bit.h" #include "taichi/common/task.h" #include "taichi/gui/gui.h" +#include "taichi/util/bit.h" #if defined(TI_GUI_COCOA) -#include "taichi/platform/mac/objc_api.h" - #include #include #include #include +#include "taichi/platform/mac/objc_api.h" + // https://stackoverflow.com/questions/4356441/mac-os-cocoa-draw-a-simple-pixel-on-a-canvas // http://cocoadevcentral.com/d/intro_to_quartz/ // Modified based on @@ -134,6 +134,10 @@ constexpr int NSApplicationActivationPolicyRegular = 0; constexpr int NSEventTypeKeyDown = 10; constexpr int NSEventTypeKeyUp = 11; +// We need to give the View class a somewhat unique name, so that it won't +// conflict with other modules (e.g. matplotlib). See issue#998. +constexpr char kTaichiViewClassName[] = "TaichiGuiClass"; + } // namespace extern id NSApp; @@ -204,7 +208,8 @@ Class ViewClass; Class AppDelClass; __attribute__((constructor)) static void initView() { - ViewClass = objc_allocateClassPair((Class)objc_getClass("NSView"), "View", 0); + ViewClass = objc_allocateClassPair((Class)objc_getClass("NSView"), + kTaichiViewClassName, 0); // There are two ways to update NSView's content, either via "drawRect:" or // "updateLayer". Updating via layer can be a lot faster, so we use this // method. See also: @@ -258,7 +263,7 @@ void GUI::create_window() { (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false); - view = call(clscall("View", "alloc"), "initWithFrame:", rect); + view = call(clscall(kTaichiViewClassName, "alloc"), "initWithFrame:", rect); gui_from_id[view] = this; // Use layer to speed up the draw // https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer?language=objc From 89d9f77f167fd482ecf8a4a2629a6c17febff116 Mon Sep 17 00:00:00 2001 From: Ye Kuang Date: Mon, 18 May 2020 21:59:30 +0900 Subject: [PATCH 2/2] [skip ci] rename --- taichi/gui/cocoa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/gui/cocoa.cpp b/taichi/gui/cocoa.cpp index 584399b66a578..ad5156b7f0488 100644 --- a/taichi/gui/cocoa.cpp +++ b/taichi/gui/cocoa.cpp @@ -136,7 +136,7 @@ constexpr int NSEventTypeKeyUp = 11; // We need to give the View class a somewhat unique name, so that it won't // conflict with other modules (e.g. matplotlib). See issue#998. -constexpr char kTaichiViewClassName[] = "TaichiGuiClass"; +constexpr char kTaichiViewClassName[] = "TaichiGuiView"; } // namespace