我的C ++应用程序嵌入了Python解释器,但在关闭时似乎遇到了一些麻烦。在主窗口关闭后,我得到一个分段错误(这是Windows,但无论如何我们称之为分段错误)。堆栈跟踪如下:
#0 102AD580 tk85!Tk_MainWindow() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#1 103082DD tk85!XSetStipple() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#2 102214A3 ??() (C:\Users\...1.3\bin\Debug\lib\tk85.dll:??)
#3 10220000 ??() (??:??)
#4 00000000 ??() (??:??)
我甚至会在哪里开始调试这个问题?它似乎是可重复的。
首先,我让你知道I identified race conditions in Python's Tkinter when used with nonthreaded Tcl/Tk (Py2 is shipped with that) and proposed a fix。我不确定我是否修复了所有可能的竞争条件,但我确实解决了所有遇到的问题。
现在,为了能够调试Tcl / Tk问题,您需要使用Tcl / Tk的调试版本构建Python并嵌入它。这应该让你能够在调试器中查看tk*.dll
,看看有什么问题。
--- a/PCbuild/prepare_tcltk.bat
+++ b/PCbuild/prepare_tcltk.bat
@@ -46,10 +46,10 @@ rem if ERRORLEVEL 1 (echo Cannot locate python.exe on PATH or as PYTHON variable
call "%PCBUILD%\get_externals.bat" --tkinter-src %ORG_SETTING%
-%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=Win32
-%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=Win32
-%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=Win32
+%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=Win32
+%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=Win32
+%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=Win32
-%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=x64
-%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=x64
-%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=x64
+%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=x64
+%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=x64
+%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=x64
PCBuild\prepare_tcltk.bat
从源代码下载并构建Tcl / Tk
请注意Tk (and Tix) can't be built with recent versions of WinSDK and will need to be patched。因此运行.bat
(它将失败),修补下载的源并再次运行它。PCBuild\readme.txt
有说明)。