奇怪的是,在调试模式下,如果脚本停止(通过断点),在没有断点的情况下通常会发生的段错误就不会发生了。非常奇怪,对吧?
这个项目使用PyCharm和Pygame。操作系统是Windows 10。该项目包含8个模块、大约1500行代码,调试一直很顺利,直到现在。
运行脚本时(非调试模式),不会出现分段错误。以下是终端在出现分段错误时的输出:
Fatal Python error: pygame_parachute: (pygame parachute) Segmentation Fault
Python runtime state: initialized
#some other threads here
Thread 0x0000490c (most recent call first):
... a long stack trace
Thread 0x00002c98 (most recent call first):
... a long stack trace
Thread 0x000048ec (most recent call first):
... a long stack trace
Current thread 0x000020d0 (most recent call first):
File "C:\Users\Solaire\PycharmProjects\Game2\ai.py", line 60 in do_ai
**File "C:/Users/Solaire/PycharmProjects/Game2/main.py", line 45 in <module>**
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18 in execfile
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483 in _exec
Extension modules:
...lots of extensions...
Process finished with exit code -1073740791 (0xC0000409)
我能立刻想到的唯一一件事就是在模块main.py中使用正斜杠。下面的堆栈帧似乎考虑文件名:
#execute the script (note: it's important to compile first to have the filename set in debug mode)
exec(compile(contents+"\n", file, 'exec'), glob, loc)
调试器的文件名是否错误?这是我得到的唯一提示。我是Python开发的新手。即使您没有完整的答案,任何帮助/提示都将不胜感激。