cztomczak / cefpython

Python bindings for the Chromium Embedded Framework (CEF)
Other
3.08k stars 473 forks source link

[gtk3.py] [Mac] Crashes with message "_createMenuRef called.." #310

Open cztomczak opened 7 years ago

cztomczak commented 7 years ago

This crash occurs due to CefInitialize / CefDoMessageLoopWork calls. It crashes even when no browser is being embedded. When CefInitialize call is removed the crash disappears.

A similar issue was reported on CEF Forum: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11827

I've found some information on web suggesting that creating a menu in app should resolve issue, but it didn't.

It should also be noted that on Mac the gtk3.py example doesn't yet implement obtaining window handle (nsview pointer) due to missing funcionality in pygobject. However this is not the cause of the crash.

Complete logs:

2017-03-02 15:08:31.478 Python[63135:d07] _createMenuRef called with existing principal MenuRef already associated with menu
2017-03-02 15:08:31.481 Python[63135:d07] (
   0   CoreFoundation                      0x00007fff8e35125c __exceptionPreprocess + 172
   1   libobjc.A.dylib                     0x00007fff8ed14e75 objc_exception_throw + 43
   2   CoreFoundation                      0x00007fff8e35110c +[NSException raise:format:] + 204
   3   AppKit                              0x00007fff8d112cf4 -[NSCarbonMenuImpl _createMenuRef] + 62
   4   AppKit                              0x00007fff8d1126ca -[NSCarbonMenuImpl _instantiateCarbonMenu] + 143
   5   AppKit                              0x00007fff8d110e92 -[NSApplication finishLaunching] + 876
   6   AppKit                              0x00007fff8d1107f3 -[NSApplication run] + 128
   7   Chromium Embedded Framework         0x0000000107b9733e cef_time_delta + 1919022
   8   Chromium Embedded Framework         0x0000000107b969dc cef_time_delta + 1916620
   9   Chromium Embedded Framework         0x0000000107bafa73 cef_time_delta + 2019171
   10  Chromium Embedded Framework         0x000000010794365d ChromeAppModeStart_v4 + 1177485
   11  cefpython_py27.so                   0x00000001064077fd _ZL43__pyx_pf_14cefpython_py27_30MessageLoopWorkP7_object + 285
   12  cefpython_py27.so                   0x00000001064076d1 _ZL43__pyx_pw_14cefpython_py27_31MessageLoopWorkP7_objectS0_ + 33
   13  Python                              0x0000000105f4bd22 PyEval_EvalFrameEx + 26683
   14  Python                              0x0000000105f45356 PyEval_EvalCodeEx + 1608
   15  Python                              0x0000000105ee906e function_call + 349
   16  Python                              0x0000000105ecace5 PyObject_Call + 99
   17  Python                              0x0000000105ed5ae0 instancemethod_call + 174
   18  Python                              0x0000000105ecace5 PyObject_Call + 99
   19  Python                              0x0000000105f4fd07 PyEval_CallObjectWithKeywords + 93
   20  _gi.so                              0x000000010e913f05 _pygi_closure_handle + 905
   21  libffi.6.dylib                      0x000000010eabe5b3 ffi_closure_unix64_inner + 662
   22  libffi.6.dylib                      0x000000010eabeab6 ffi_closure_unix64 + 70
   23  libglib-2.0.0.dylib                 0x000000010e9e9cab g_main_context_dispatch + 274
   24  libglib-2.0.0.dylib                 0x000000010e9e9f99 g_main_context_iterate + 413
   25  libglib-2.0.0.dylib                 0x000000010e9e9ff1 g_main_context_iteration + 55
   26  libgio-2.0.0.dylib                  0x000000010eb96a08 g_application_run + 399
   27  libffi.6.dylib                      0x000000010eabe934 ffi_call_unix64 + 76
   28  ???                                 0x00007fff59d43160 0x0 + 140734700466528
)
cztomczak commented 7 years ago

Someone on CEF Forum says he resolved the issue by getting rid of a double call to NSApp.finishLaunching. Quote:

It seems to happen in apps that call [NSApp finishLaunching], enter their own message loop (instead of [NSApp run]) and then CefDoMessageLoopWork() (which eventually calls [NSApp run], which calls finishLaunching.) The double call to finishLaunching is what breaks things. Apps that don't call [NSApp run] should avoid calling [NSApp finishLaunching] if they are ever going to call CefDoMessageLoopWork().

Ref: http://magpcss.org/ceforum/viewtopic.php?p=36375#p36375

See .mm demo app that shows how to avoid problem: https://github.com/dankegel/tinycef/blob/50bd38d5395c46a47a1aa6c5db112526c95038b1/tiny.mm