在MacOs Mojave上创建OpenGL窗口后尝试使用tk.Tk()时Python崩溃

时间:2018-11-20 15:53:41

标签: python opengl tkinter glfw macos-mojave

我面临以下问题: 使用OpenGL渲染后,我试图启动tk窗口,但是python似乎崩溃了(每次)。 正在运行:

    import tkinter as tk
    tk.Tk()

产生一个小窗口并且没有崩溃。 正在运行:

    import glfw
    assert glfw.init()
    glfw.window_hint(glfw.VISIBLE, False)
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3);
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2);
    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, 1);
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
    window = glfw.create_window(100, 100, "hidden window", None, None)

,然后使用该窗口进行计算也可以正常工作。 但是,同时运行它们,就像这样:

    import glfw
    import tkinter as tk
    assert glfw.init()
    glfw.window_hint(glfw.VISIBLE, False)
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3);
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2);
    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, 1);
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
    window = glfw.create_window(100, 100, "hidden window", None, None)
    tk.Tk()

导致崩溃:

2018-11-20 09:21:38.466 Python[52111:1218385] -[GLFWApplication _setup:]: unrecognized selector sent to instance 0x7fb1b6febf10
2018-11-20 09:21:38.468 Python[52111:1218385] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GLFWApplication _setup:]: unrecognized selector sent to instance 0x7fb1b6febf10'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff4b756e65 __exceptionPreprocess + 256
    1   libobjc.A.dylib                     0x00007fff777ad720 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff4b7d422d -[NSObject(NSObject) __retain_OA] + 0
    3   CoreFoundation                      0x00007fff4b6f8820 ___forwarding___ + 1486
    4   CoreFoundation                      0x00007fff4b6f81c8 _CF_forwarding_prep_0 + 120
    5   libtk8.6.dylib                      0x000000011b24c1f2 TkpInit + 408
    6   libtk8.6.dylib                      0x000000011b1bbaac Initialize + 2454
    7   _tkinter.cpython-36m-darwin.so      0x000000011a067dd4 Tcl_AppInit + 84
    8   _tkinter.cpython-36m-darwin.so      0x000000011a067aab _tkinter_create + 1115
    9   Python                              0x000000010de60e1b _PyCFunction_FastCallDict + 491
    10  Python                              0x000000010dee3a87 call_function + 439
    11  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    12  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    13  Python                              0x000000010dee50bb _PyFunction_FastCallDict + 763
    14  Python                              0x000000010de17e57 _PyObject_FastCallDict + 247
    15  Python                              0x000000010de17f75 _PyObject_Call_Prepend + 149
    16  Python                              0x000000010de17c90 PyObject_Call + 96
    17  Python                              0x000000010de7904d slot_tp_init + 125
    18  Python                              0x000000010de75279 type_call + 313
    19  Python                              0x000000010de17e25 _PyObject_FastCallDict + 197
    20  Python                              0x000000010dee3988 call_function + 184
    21  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    22  Python                              0x000000010dee4cfd fast_function + 381
    23  Python                              0x000000010dee3a61 call_function + 401
    24  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    25  Python                              0x000000010dee4cfd fast_function + 381
    26  Python                              0x000000010dee3a61 call_function + 401
    27  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    28  Python                              0x000000010dee4cfd fast_function + 381
    29  Python                              0x000000010dee3a61 call_function + 401
    30  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    31  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    32  Python                              0x000000010ded9584 PyEval_EvalCode + 100
    33  Python                              0x000000010ded6c04 builtin_exec + 548
    34  Python                              0x000000010de60e1b _PyCFunction_FastCallDict + 491
    35  Python                              0x000000010dee3a87 call_function + 439
    36  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    37  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    38  Python                              0x000000010dee4da1 fast_function + 545
    39  Python                              0x000000010dee3a61 call_function + 401
    40  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    41  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    42  Python                              0x000000010dee4da1 fast_function + 545
    43  Python                              0x000000010dee3a61 call_function + 401
    44  Python                              0x000000010dee0296 _PyEval_EvalFrameDefault + 27718
    45  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    46  Python                              0x000000010ded9584 PyEval_EvalCode + 100
    47  Python                              0x000000010ded6c04 builtin_exec + 548
    48  Python                              0x000000010de60e1b _PyCFunction_FastCallDict + 491
    49  Python                              0x000000010dee3a87 call_function + 439
    50  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    51  Python                              0x000000010dee4cfd fast_function + 381
    52  Python                              0x000000010dee3a61 call_function + 401
    53  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    54  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    55  Python                              0x000000010dee4da1 fast_function + 545
    56  Python                              0x000000010dee3a61 call_function + 401
    57  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    58  Python                              0x000000010dee4cfd fast_function + 381
    59  Python                              0x000000010dee3a61 call_function + 401
    60  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    61  Python                              0x000000010dee4cfd fast_function + 381
    62  Python                              0x000000010dee3a61 call_function + 401
    63  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    64  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    65  Python                              0x000000010dee4da1 fast_function + 545
    66  Python                              0x000000010dee3a61 call_function + 401
    67  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    68  Python                              0x000000010dee4cfd fast_function + 381
    69  Python                              0x000000010dee3a61 call_function + 401
    70  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    71  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    72  Python                              0x000000010dee4da1 fast_function + 545
    73  Python                              0x000000010dee3a61 call_function + 401
    74  Python                              0x000000010dee01f7 _PyEval_EvalFrameDefault + 27559
    75  Python                              0x000000010dee44ef _PyEval_EvalCodeWithName + 2447
    76  Python                              0x000000010ded9584 PyEval_EvalCode + 100
    77  Python                              0x000000010df0f5f1 PyRun_FileExFlags + 209
    78  Python                              0x000000010df0ee62 PyRun_SimpleFileExFlags + 882
    79  Python                              0x000000010df28db2 Py_Main + 3554
    80  Python                              0x000000010de05df8 Python + 3576
    81  libdyld.dylib                       0x00007fff7887c08d start + 1
    82  ???                                 0x0000000000000004 0x0 + 4
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
  • 我的环境如下:
    MacOs 10.14.1 python 3.6.7 ActiveCTL 8.6(使用tk.CtlVersion检查) OpenGL使用-4.1([根据glOString的检查(为了实现这一点,并且不使用默认的2.1版本,根据MacO的一些stackoverflow提示,我添加了所有window_hints)

  • 我已经尝试过的事情:
    通过切换到ActivePython 3.6.5将activeCTL降级到8.5(因为我看到一些对ctl的SO引用在MacOS上有问题,应该可以解决这个问题)


更新:

我发现反转2个方法调用可以“解决”问题-程序不会崩溃。知道为什么吗?

0 个答案:

没有答案