opened
zzj1213
username_0
Also, **TouchBar** appeared multiple times in the crash reports.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	0x00007fff6937604c class_conformsToProtocol + 235
1   libobjc.A.dylib               	0x00007fff69375f46 -[NSObject conformsToProtocol:] + 46
2   com.apple.AppKit              	0x00007fff3c8f26b9 -**[NSApplication(NSTouchBarFinder) NS_touchBarProviders]** + 403
3   com.apple.AppKit              	0x00007fff3c8f37ad _NSTouchBarFinderGatherProvidersForContainer + 64
4   com.apple.AppKit              	0x00007fff3c8f2dd2 ___NSTouchBarFinderSetNeedsUpdateOnMain_block_invoke + 279
5   com.apple.CoreFoundation      	0x00007fff3ec53f28 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
6   com.apple.CoreFoundation      	0x00007fff3ec53e5d __CFRunLoopDoObservers + 451
7   com.apple.CoreFoundation      	0x00007fff3ebf5ef9 CFRunLoopRunSpecific + 514
8   com.apple.HIToolbox           	0x00007fff3de551ab RunCurrentEventLoopInMode + 292
9   com.apple.HIToolbox           	0x00007fff3de54ded ReceiveNextEventCommon + 355
10  com.apple.HIToolbox           	0x00007fff3de54c76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
11  com.apple.AppKit              	0x00007fff3c1ed79d _DPSNextEvent + 1135
12  com.apple.AppKit              	0x00007fff3c1ec48b -**[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]** + 1361
13  com.ABC.XYZ        	0x00000001012eb96c main + 5420
14  libdyld.dylib                 	0x00007fff6ab4c3d5 start + 1
MAC version crashed on high resolution screen
issue
created
JBildstein
username_1
I had the same problem in my project an fixed it by using `NSResponder` as the parent for the app delegate and also add the `NSTouchBarProvider` protocol to it.

I believe replacing this line: https://github.com/username_2/webview/blob/9c1b0a888aa40039d501c1ea9f60b22a076a25ea/webview.h#L1920
with this:
```cpp
  Class __NSWindowDelegate = objc_allocateClassPair(objc_getClass("NSResponder"),
                                                    "__NSWindowDelegate", 0);
  class_addProtocol(__NSWindowDelegate, objc_getProtocol("NSTouchBarProvider"));
```
should fix it.
comment
created
zserge
username_2
Hm... I tried what @username_1 suggested, but so far the crash is still there, even though I use NSResponder as the parent class to my delegate. And he's right, the crash happens only on the devices with the touchbar. I wish I knew macos internals better to debug this.
comment
created
JBildstein
username_1
did you add the `NSTouchBarProvider` protocol as well (and made sure `objc_getProtocol` actually returns a valid pointer)?

to debug this I found the XCode touchbar emulator very helpful: open XCode and in the menu select "Window->Show Touch Bar" in XCode 10 or "Window->Touch Bar->Show Touch Bar" in XCode 11.
comment
created
zserge
username_2
Unfortunately, still no luck. I only did the following modification:

```diff
diff --git a/webview.h b/webview.h
index 19e69b6..821b435 100644
--- a/webview.h
+++ b/webview.h
@@ -585,7 +585,9 @@ public:
                  NSApplicationActivationPolicyRegular);
 
     // Delegate
-    auto cls = objc_allocateClassPair((Class) "NSObject"_cls, "AppDelegate", 0);
+    auto cls = objc_allocateClassPair((Class) "NSResponder"_cls, "AppDelegate", 0);
+    printf("%p\n", objc_getProtocol("NSTouchBarProvider"));
+    class_addProtocol(cls, objc_getProtocol("NSTouchBarProvider"));
     class_addProtocol(cls, objc_getProtocol("NSApplicationDelegate"));
     class_addProtocol(cls, objc_getProtocol("WKScriptMessageHandler"));
     class_addMethod(cls, "applicationShouldTerminateAfterLastWindowClosed:"_sel,
```

And I get a crash, although the protocol for NSTouchBarProvider is non-zero.
comment
created
JBildstein
username_1
ok I figured it out. I forgot about one small detail (and actually thought it would behave differently with c/c++):

both `NSApplicationDelegate` and `WKScriptMessageHandler` return null in `objc_getProtocol` and adding null with `class_addProtocol` causes weird problems with the internal `conforms_to_protocol` check that's causing the exception.

So the solution is to remove the `class_addProtocol` calls with `NSApplicationDelegate` and `WKScriptMessageHandler`

I had the same issue in C# but I figured those protocols simply aren't available at runtime but they would be at compile time. seems I was wrong.
comment
created
zserge
username_2
@username_1 Sir, you are a genius! Thanks a lot :tada:
comment
closed
zserge
username_2
issue