Menu

#20 image delete

tclBlend2d 1.x
Fixed
1.7 (2)
4 days ago
2026-07-29
No

When I'm about to destroy my label, I want to destroy my image , and that's when I get a crash.

proc onWidgetDestroy {img} {
    image delete $img
}

package req Blend2d

set img [image create blend2d -format [list 100 100 PRGB32]]
label .l -image $img -borderwidth 0 -anchor nw

pack .l -padx 0 -pady 0 -expand 1 -fill both

bind .l <Destroy> {onWidgetDestroy $img}

Discussion

  • Aldo Buratti

    Aldo Buratti - 2026-07-30

    I can't reproduce the crash on Windows. Everyting works as expected. (Blend2d 1.7)
    Same on Mac (Intel) and Ubuntu.

    The differencies between Mac/Windows/Linux are really minimals, just few lines in tkImgBlend2d.c., and up to now the only difference (solved few years ago) was that on Mac we had blue and red swapped ... Fixed with a bug-fix on the tcltk core.

    • Are you running on Mac ? Silicon Mac ?
    • Which TclTk version are you using ?

    I ask you because Blend2d it's not tested on the latest versions of TclTk, and regarding Mac, I only have an old Mac-Intel.

    Please let me know these deatails, I will try to do more specific tests.

     
  • Nicolas Robert

    Nicolas Robert - 2026-07-31

    Are you running on Mac ? Silicon Mac ?

    Yes , but I also have this issue on Windows

    Which TclTk version are you using ?

    9.0.3

    If it's very easy to compile your version, I could try to create a DLL in debug mode.
    And see if there's any additional information.

    Do you know of a place where I could read about how to compile tclBlend2D?

     
  • Aldo Buratti

    Aldo Buratti - 2026-07-31

    Downlod the tclBlend2d-devkit
    https://sourceforge.net/p/irrational-numbers/code/HEAD/tree/pkgs/tclBlend2D-devkit/tags/1.7/
    or
    https://sourceforge.net/p/irrational-numbers/code/HEAD/tree/pkgs/tclBlend2D-devkit/tags/1.8/

    The devkit also contains a prebuilt dll/dylib of the 'core' blend2d and also the include/stubs for TclTk (8.x and 9.x)

    Note: release 1.8 introduces significant changes specifically in tkImgBlend2d.c, which should be the critical point where images are created and destroyed. I suggest to start with release 1.7

    Quick instructions are in "HowToBuild.txt"

    • On Windows, I suggest to try first with
      ms-build tcl-9
      it should be enough (You will get the full deployable under the XBUILD directory)

    • If it's OK, clean the XBUILD directory before recompiling for debug:
      set CFLAGS=/Zi /Od
      set LFLAGS=/DEBUG
      ms-build tcl-9

    • For debugging on MacOS
      set CFLAGS=-g -O0
      ./build.sh tcl-9 arm64

    Let me know if you have problems, it’s been years since I last compiled in debug mode.

     
  • Nicolas Robert

    Nicolas Robert - 2026-08-03

    I have successfully compiled in debug mode (on Windows, v1.7).

    And look below when the window closes :

    tcl9tk90.dll (crash)
    tkb2d90.dll!getImgSurfaceMaster
    tkb2d90.dll!MasterSurfaceDeleteImage  (tkImgBlend2d.c:272)
    tkb2d90.dll!BLX_Surface::~BLX_Surface()  (t2d_Surface.cxx:164)
    tkb2d90.dll!DeleteB2dMetadata  (t2d_Surface.cxx:737)
    tkb2d90.dll!ImgSurfaceDelete  (tkImgBlend2d.c:310)
    

    It would appear that nothing offers protection against this re-entry :

    static
    ImgSurfaceMaster* getImgSurfaceMaster(Tcl_Interp* interp, Tk_ImageMaster tkmaster) {
        const Tk_ImageType* dummy;
        const char* name = Tk_NameOfImage(tkmaster);
        if (name==NULL) { return NULL; }
        /*
    
         * I've got a breakdown here
         */
        ImgSurfaceMaster* masterPtr = (ImgSurfaceMaster*)Tk_GetImageMasterData(interp,name,&dummy);
        return masterPtr;
    }
    

    Well, I don’t know if this will help you, but it seems to match my crash.

     
  • Aldo Buratti

    Aldo Buratti - 6 days ago

    Sorry, but I cannot reproduce your bug.
    I'm on Windows , with TclTk 9.0.3 , using Blend2d 1.7

    I also added this line to your script
    after 2000 { puts "deleting label" ; destroy .l ; puts "done" }

    and everything works as expected (no crash).

    I suspect our TclTk 9.0.3 are not the same; mine is dated at the end of 2025, and I noticed that some parts of the Tk-core library have been updated recently.
    More specifically tkImage.c was updated on February 2026, and this could be the reason of the your (new?) TclTk 9.0.3 crash.

    Can you inspect the timestamp of your "wish90.exe" ?
    Or, can you run your script with an older version of TclTk (< 9.0.3) ?

    If my guess is correct, then something has changed in the Tk core.

     
  • Nicolas Robert

    Nicolas Robert - 6 days ago

    Can you inspect the timestamp of your "wish90.exe" ?

    My version is from December 2025

    after 2000 { puts "deleting label" ; destroy .l ; puts "done" }

    It’s the same for me – I’ve got no problem with that command, it’s only when I close the window.

    Or, can you run your script with an older version of TclTk (< 9.0.3) ?

    The problem still persists (9.0.1)

    It doesn't matter – in a way, that's just as well.

    Thanks

    Regards

     
  • Aldo Buratti

    Aldo Buratti - 6 days ago

    Now I understand.
    The problem is only when you destroy the root window "." !!! Correct ?
    This imply that the whole application is terminated ...

    The strange thing is that on my PC there's no crash, but the application takes 3..6 seconds to close.
    Without the "bind .l <destroy> {onWidgetDestroy $img}", the application quits immediatly.</destroy>

    This is a (weird) case that I should examine, and maybe fix!
    In the meantime, I have this simple/silly workaround at Tcl level:


    package require Tk
    set ::TK ON
    bind . <destroy> {set ::TK "OFF"} </destroy>

    proc onWidgetDestroy {img} {
    if {$::TK_STATUS eq "ON" } {
    image delete $img
    }
    }

    package req Blend2d

    set img [image create blend2d -format [list 100 100 PRGB32]]
    label .l -image $img -borderwidth 0 -anchor nw

    pack .l -padx 0 -pady 0 -expand 1 -fill both

    bind .l <destroy> {onWidgetDestroy $img}</destroy>

    # UNCOMMENT THIS ..
    # destroy .

    Now the application (if launched by tclsh) should be already running, even without the wholeTk .


     
  • Nicolas Robert

    Nicolas Robert - 6 days ago

    The problem is only when you destroy the root window "." !!! Correct ?

    Yes !

    The strange thing is that on my PC there's no crash, but the application takes 3..6 seconds to close.

    Same , but I think there’s still a bug, because if you add a puts after the delete command, you’ll never see it show up.

     
  • Aldo Buratti

    Aldo Buratti - 4 days ago

    I think version 1.8 fixes this bug.
    See announce and download link at https://wiki.tcl-lang.org/page/Blend2d

    Please, run a test on Mac-Silicon.

     
  • Nicolas Robert

    Nicolas Robert - 4 days ago

    I think version 1.8 fixes this bug.

    It works

    Thank you

     
  • Aldo Buratti

    Aldo Buratti - 4 days ago
    • status: New --> Fixed
     

Log in to post a comment.