[Tkinter-discuss] Segfault in Image.PhotoImage on OS X
Marc Culler
marc.culler at gmail.com
Thu Apr 26 17:50:59 CEST 2012
This was reported here in February, but no debugging information was
provided by the reporter:
http://stackoverflow.com/questions/9142786/python-imagetk-photoimage-segfault
<view-source:http://stackoverflow.com/questions/9142786/python-imagetk-photoimage-segfault>
I can explain the nature of the problem, but I don't know how to fix
it correctly.
I am using the standard x86_64 Python 2.7.2 package from python.org and I have
installed Active State Tcl/Tk 8.11.
When I tried using easy_install to install PIL it would not load,
claiming that _imaging.so
did not exist. In fact, it existed but was only a thin i386
executable. So I compiled
Imaging-1.1.7 with
export CFLAGS='-arch i386 -arch x86_64'
and
export TCL_ROOT=/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl
I was then able to load the module. However, the following code
produced a segfault:
import Image
import ImageTk
import Tkinter
W = Tkinter.Tk()
Im = Image.open('test_image.jpg')
x = ImageTk.PhotoImage(Im)
The crash occurs in Tk_GetImageMasterData. More importantly, though,
the crash was
preceded by the following messages:
objc[36554]: Class TKApplication is implemented in both
/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined.
objc[36554]: Class TKMenu is implemented in both
/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined.
objc[36554]: Class TKContentView is implemented in both
/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined.
objc[36554]: Class TKWindow is implemented in both
/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the
two will be used. Which one is undefined.
Guessing that PIL was finding the
System/Library/Frameworks/Tk.Framework instead of
/Library/Frameworks/Tk.Framework, I tried hiding the system Tcl and Tk
frameworks by
renaming them. I was then able to create the PhotoImage and display it.
I don't know where those messages come from, and I have never
encountered them before.
But I am guessing they are from OS X, since they are generated by an
objective C program.
Evidently _tkinter.so is able to specify which Tk.Framework to use. I
don't know its
mechanism for doing that. But, somehow, PIL is not doing it, and it
ends up using the
wrong one.
A stack trace of the crash is below.
- Marc
0x000000011517bccd in Tk_GetImageMasterData ()
(gdb) bt
#0 0x000000011517bccd in Tk_GetImageMasterData ()
#1 0x0000000115183d9f in Tk_FindPhoto ()
#2 0x00000001014fbadc in PyImagingPhotoPut ()
#3 0x000000011502a05b in TclInvokeStringCommand ()
#4 0x000000010102142a in TclEvalObjvInternal ()
#5 0x000000010102261c in Tcl_EvalObjv ()
#6 0x000000010100646d in Tkapp_Call ()
#7 0x00000001000c102d in PyEval_EvalFrameEx ()
#8 0x00000001000c2d29 in PyEval_EvalCodeEx ()
#9 0x00000001000c0b6a in PyEval_EvalFrameEx ()
#10 0x00000001000c2d29 in PyEval_EvalCodeEx ()
#11 0x000000010003da80 in function_call ()
#12 0x000000010000c5e2 in PyObject_Call ()
#13 0x000000010001ebcb in instancemethod_call ()
#14 0x000000010000c5e2 in PyObject_Call ()
#15 0x00000001000ba5f7 in PyEval_CallObjectWithKeywords ()
#16 0x0000000100021e5e in PyInstance_New ()
#17 0x000000010000c5e2 in PyObject_Call ()
#18 0x00000001000be5f3 in PyEval_EvalFrameEx ()
#19 0x00000001000c2d29 in PyEval_EvalCodeEx ()
#20 0x00000001000c2e46 in PyEval_EvalCode ()
#21 0x00000001000e769c in PyRun_InteractiveOneFlags ()
#22 0x00000001000e78fe in PyRun_InteractiveLoopFlags ()
#23 0x00000001000e80e1 in PyRun_AnyFileExFlags ()
#24 0x00000001000fe77c in Py_Main ()
#25 0x0000000100000f14 in dyld_stub_strlen ()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20120426/4a012ee8/attachment.html>
More information about the Tkinter-discuss
mailing list