Tk Source Code

View Ticket
Login
Ticket UUID: 1424367
Title: image item with activeimage and bind to destroy - drag crash
Type: Bug Version: obsolete: 8.4.12
Submitter: lio_lion Created on: 2006-02-05 04:11:16
Subsystem: 04. Canvas Basics Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2019-09-04 20:10:25
Resolution: Fixed Closed By: fvogel
    Closed on: 2019-09-04 20:10:25
Description:
If you create an image item in a canvas that contains
an activeimage, then you bind it so that it is
destroyed when you click it. It is fine if you just
click on it (it will be destroyed) but if you click and
drag off it then it will cause a crash.

Here is a very short test app that shows this note you
need to have an image in the same folder, any image
should do (either name it close.gif, or change the link
in the code). If you click on the image it destroys it,
if you click on the image and drag off it - crash:

pack [canvas .c]
set i [image create photo -file close.gif]
.c create image 20 20 -anchor nw -image $i -activeimage
$i -tag c1text
.c bind c1text <ButtonRelease-1> "destroy .c"

#note, you can get around the bug by replacing either
(or both) of the last 2 lines with these:
#.c create image 20 20 -anchor nw -image $i -tag c1text
#.c bind c1text <ButtonRelease-1> "after 0 \"destroy .c\""


Just to note I ran this under windows using the
binaries from Activestate under Tcl/Tk 8.4.11, however
I got a friend to test it under linux 8.4.11 and 8.4.12
and he said that it causes a crash under both cause, he
also was able to give me the callstack (not sure if it
was for 8.4.11 or 8.4.12) although it is pretty
intuitive what this crash is probably caused by...
Program received signal SIGSEGV, Segmentation fault.
0x005ba93c in Tk_CanvasEventuallyRedraw () from
/usr/lib/libtk8.4.so
(gdb) bt
#0  0x005ba93c in Tk_CanvasEventuallyRedraw () from
/usr/lib/libtk8.4.so
#1  0x005bc860 in Tk_CreateItemType () from
/usr/lib/libtk8.4.so
#2  0x005bd06e in Tk_CreateItemType () from
/usr/lib/libtk8.4.so
#3  0x00581766 in Tk_HandleEvent () from
/usr/lib/libtk8.4.so
#4  0x00581c44 in Tk_HandleEvent () from
/usr/lib/libtk8.4.so
#5  0x001dc3f3 in Tcl_ServiceEvent () from
/usr/lib/libtcl8.4.so
#6  0x001dc68f in Tcl_DoOneEvent () from
/usr/lib/libtcl8.4.so
#7  0x00581088 in Tk_MainLoop () from /usr/lib/libtk8.4.so
#8  0x0058e9f7 in Tk_MainEx () from /usr/lib/libtk8.4.so
#9  0x080487e4 in main ()
User Comments: fvogel added on 2019-09-04 20:10:25:
Merged to core-8-6-branch and trunk.

fvogel added on 2019-09-02 20:52:10:

Reproduced with current core-8-6-branch on Windows. The call stack is:

>	tk86tg.dll!EventuallyRedrawItem(TkCanvas * canvasPtr=0x0081e130, Tk_Item * itemPtr=0x0064ff68)  Line 2899 + 0x4c bytes	C
 	tk86tg.dll!PickCurrentItem(TkCanvas * canvasPtr=0x0081e130, _XEvent * eventPtr=0x006bd860)  Line 5007 + 0xd bytes	C
 	tk86tg.dll!CanvasBindProc(void * clientData=0x0081e130, _XEvent * eventPtr=0x006bd860)  Line 4794 + 0xd bytes	C
 	tk86tg.dll!Tk_HandleEvent(_XEvent * eventPtr=0x006bd860)  Line 1283 + 0x15 bytes	C
 	tk86tg.dll!WindowEventProc(Tcl_Event * evPtr=0x006bd858, int flags=-3)  Line 1695 + 0xc bytes	C
 	tcl86tg.dll!Tcl_ServiceEvent(int flags=-3)  Line 670 + 0xd bytes	C
 	tcl86tg.dll!Tcl_DoOneEvent(int flags=-3)  Line 967 + 0x9 bytes	C
 	tk86tg.dll!Tk_MainLoop()  Line 2079 + 0x11 bytes	C
 	tcl86tg.dll!Tcl_MainExW(int argc=-1, unsigned short * * argv=0x00311bec, int (Tcl_Interp *)* appInitProc=0x004010a0, Tcl_Interp * interp=0x00795de8)  Line 576 + 0x5 bytes	C
 	tclsh86tg.exe!wmain(int argc=1, unsigned short * * argv=0x00311be8)  Line 131 + 0x25 bytes	C
 	tclsh86tg.exe!__tmainCRTStartup()  Line 579 + 0x19 bytes	C
 	tclsh86tg.exe!wmainCRTStartup()  Line 399	C
 	kernel32.dll!7587f964() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!77cae369() 	
 	ntdll.dll!77cae57b() 	

It crashes because in EventuallyRedrawItem() on line 2899 canvasPtr->tkwin is NULL. Since the canvas is half-destroyed at this point, EventuallyRedrawItem() should bail out early since there is nothing to redraw: this is [8ff82b95a9].