1

我正在编写的 Pygame 测试程序中出现了一个奇怪的问题。我已将其简化为这个测试用例:

import pygame
import turtle

pygame.init()
window = pygame.display.set_mode((800, 800))

tile = pygame.Surface((800, 800))
tile.fill((255,255,255))

finished = False
while not finished:
    window.fill((255,255,255))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True

    window.blit(tile, (0,0))
    pygame.display.flip()

t = turtle.Turtle()
t.color('green')
t.dot()

测试用例实际上并没有做任何事情——它只是显示一个白屏。当您关闭白屏时,它应该使用 Turtle 绘制一个绿点。相反,Python 崩溃了,我得到了这个堆栈跟踪:

2013-09-03 22:53:17.263 Python[38648:f07] -[SDLApplication _setup:]: unrecognized selector sent to instance 0x1095228f0
2013-09-03 22:53:17.264 Python[38648:f07] An uncaught exception was raised
2013-09-03 22:53:17.264 Python[38648:f07] -[SDLApplication _setup:]: unrecognized selector sent to instance 0x1095228f0
2013-09-03 22:53:17.266 Python[38648:f07] (
    0   CoreFoundation                      0x00000001002d60a6 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00000001008fa3f0 objc_exception_throw + 43
    2   CoreFoundation                      0x000000010036c6ea -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
    3   CoreFoundation                      0x00000001002c45ce ___forwarding___ + 414
    4   CoreFoundation                      0x00000001002c43b8 _CF_forwarding_prep_0 + 232
    5   Tk                                  0x00000001093f05c0 TkpInit + 453
    6   Tk                                  0x000000010936ca66 Tk_Init + 1816
    7   _tkinter.so                         0x000000010923ad2b Tcl_AppInit + 75
    8   _tkinter.so                         0x00000001092381b4 Tkinter_Create + 916
    9   Python                              0x00000001000c1e7d PyEval_EvalFrameEx + 25213
    10  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    11  Python                              0x000000010003d910 function_call + 176
    12  Python                              0x000000010000c362 PyObject_Call + 98
    13  Python                              0x000000010001e97b instancemethod_call + 363
    14  Python                              0x000000010000c362 PyObject_Call + 98
    15  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    16  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    17  Python                              0x000000010003d910 function_call + 176
    18  Python                              0x000000010000c362 PyObject_Call + 98
    19  Python                              0x000000010001e97b instancemethod_call + 363
    20  Python                              0x000000010000c362 PyObject_Call + 98
    21  Python                              0x00000001000ba947 PyEval_CallObjectWithKeywords + 87
    22  Python                              0x0000000100021c0e PyInstance_New + 126
    23  Python                              0x000000010000c362 PyObject_Call + 98
    24  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    25  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    26  Python                              0x000000010003d910 function_call + 176
    27  Python                              0x000000010000c362 PyObject_Call + 98
    28  Python                              0x000000010001e97b instancemethod_call + 363
    29  Python                              0x000000010000c362 PyObject_Call + 98
    30  Python                              0x0000000100078d58 slot_tp_init + 88
    31  Python                              0x0000000100074cc5 type_call + 245
    32  Python                              0x000000010000c362 PyObject_Call + 98
    33  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    34  Python                              0x00000001000c286d PyEval_EvalFrameEx + 27757
    35  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    36  Python                              0x000000010003d910 function_call + 176
    37  Python                              0x000000010000c362 PyObject_Call + 98
    38  Python                              0x000000010001e97b instancemethod_call + 363
    39  Python                              0x000000010000c362 PyObject_Call + 98
    40  Python                              0x0000000100078d58 slot_tp_init + 88
    41  Python                              0x0000000100074cc5 type_call + 245
    42  Python                              0x000000010000c362 PyObject_Call + 98
    43  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    44  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    45  Python                              0x00000001000c4266 PyEval_EvalCode + 54
    46  Python                              0x00000001000e8ede PyRun_FileExFlags + 174
    47  Python                              0x00000001000e9199 PyRun_SimpleFileExFlags + 489
    48  Python                              0x000000010010006d Py_Main + 3085
    49  Python                              0x0000000100000f14 Python + 3860
)
2013-09-03 22:53:17.267 Python[38648:f07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDLApplication _setup:]: unrecognized selector sent to instance 0x1095228f0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001002d60a6 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00000001008fa3f0 objc_exception_throw + 43
    2   CoreFoundation                      0x000000010036c6ea -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
    3   CoreFoundation                      0x00000001002c45ce ___forwarding___ + 414
    4   CoreFoundation                      0x00000001002c43b8 _CF_forwarding_prep_0 + 232
    5   Tk                                  0x00000001093f05c0 TkpInit + 453
    6   Tk                                  0x000000010936ca66 Tk_Init + 1816
    7   _tkinter.so                         0x000000010923ad2b Tcl_AppInit + 75
    8   _tkinter.so                         0x00000001092381b4 Tkinter_Create + 916
    9   Python                              0x00000001000c1e7d PyEval_EvalFrameEx + 25213
    10  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    11  Python                              0x000000010003d910 function_call + 176
    12  Python                              0x000000010000c362 PyObject_Call + 98
    13  Python                              0x000000010001e97b instancemethod_call + 363
    14  Python                              0x000000010000c362 PyObject_Call + 98
    15  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    16  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    17  Python                              0x000000010003d910 function_call + 176
    18  Python                              0x000000010000c362 PyObject_Call + 98
    19  Python                              0x000000010001e97b instancemethod_call + 363
    20  Python                              0x000000010000c362 PyObject_Call + 98
    21  Python                              0x00000001000ba947 PyEval_CallObjectWithKeywords + 87
    22  Python                              0x0000000100021c0e PyInstance_New + 126
    23  Python                              0x000000010000c362 PyObject_Call + 98
    24  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    25  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    26  Python                              0x000000010003d910 function_call + 176
    27  Python                              0x000000010000c362 PyObject_Call + 98
    28  Python                              0x000000010001e97b instancemethod_call + 363
    29  Python                              0x000000010000c362 PyObject_Call + 98
    30  Python                              0x0000000100078d58 slot_tp_init + 88
    31  Python                              0x0000000100074cc5 type_call + 245
    32  Python                              0x000000010000c362 PyObject_Call + 98
    33  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    34  Python                              0x00000001000c286d PyEval_EvalFrameEx + 27757
    35  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    36  Python                              0x000000010003d910 function_call + 176
    37  Python                              0x000000010000c362 PyObject_Call + 98
    38  Python                              0x000000010001e97b instancemethod_call + 363
    39  Python                              0x000000010000c362 PyObject_Call + 98
    40  Python                              0x0000000100078d58 slot_tp_init + 88
    41  Python                              0x0000000100074cc5 type_call + 245
    42  Python                              0x000000010000c362 PyObject_Call + 98
    43  Python                              0x00000001000bf2c8 PyEval_EvalFrameEx + 14024
    44  Python                              0x00000001000c4149 PyEval_EvalCodeEx + 2137
    45  Python                              0x00000001000c4266 PyEval_EvalCode + 54
    46  Python                              0x00000001000e8ede PyRun_FileExFlags + 174
    47  Python                              0x00000001000e9199 PyRun_SimpleFileExFlags + 489
    48  Python                              0x000000010010006d Py_Main + 3085
    49  Python                              0x0000000100000f14 Python + 3860
)
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6

细节:

$ python --version
> Python 2.7.3
$ sw_vers
> ProductName:  Mac OS X
> ProductVersion:   10.8.2
> BuildVersion: 12C3012

我不确定如何调试它(或者即使我正在做的事情是有效的)所以欢迎任何反馈。

4

0 回答 0