ftw icon indicating copy to clipboard operation
ftw copied to clipboard

ftw crashes when alpha-blending is exported

Open dertuxmalwieder opened this issue 1 year ago • 2 comments

A curious little problem: I wrote an application with ftw and it generally works just fine (thank you for your efforts!). However, creating and using an .exe just won't work if I use alpha-blending. I can perfectly reproduce that with your own example code, as icon.lisp uses alpha-blending as well:

> sbcl --load icon.lisp

(...)

* (sb-ext:save-lisp-and-die "test.exe" :toplevel #'ftw.icon:test-icon3 :executable t)

Trying to run test.exe, the result I get in the console window is: "Error 87: wrong parameter". This is weird, as calling (ftw.icon:test-icon3) right from inside of the REPL does not have any problem, and I have no problem compiling other examples like dragdrop.lisp. What could be the culprit here?

Windows 10, 64-bit.

dertuxmalwieder avatar Jun 18 '24 17:06 dertuxmalwieder

Good question, and off the top of my head I've no idea. Quite an odd bug. I admit I never used saved images so it's not something I ever tested when I wrote it.

I will try to reproduce it.

fjames86 avatar Jun 18 '24 21:06 fjames86

Ah, I could perfectly live without the alpha blending (and/or .exe files), but the tool I wrote could be useful for other people, and those other people like 1) eye-candy and 2) pre-built binaries...

Thank you for looking into this!

dertuxmalwieder avatar Jun 18 '24 22:06 dertuxmalwieder

Ok I finally got some time to look at this. I reproduced it and identified the issue. It seems if you allocate a handle then save-lisp-and-die then all your handles are invalid. You need to instead save data arrays and allocate the handles in some sort of initialisation routine after saving the image. I updated the icon.lisp example so it now works in this scenario but it likely affects all such APIs.

fjames86 avatar Aug 02 '24 22:08 fjames86

Thank you a lot! (I know that FLOSS developers rarely get enough credits, so here's mine.)

What would be the generic way to "fix" the applications now? I looked at the diff and it looks like it's rather specific.

dertuxmalwieder avatar Aug 03 '24 00:08 dertuxmalwieder

I think you need to create all your bitmaps/icons etc. after restarting from save-lisp-and-die. Perhaps change from allocating directly in defvar/defparameter to some sort of lazy initialisation where it is allocated only on first use.

fjames86 avatar Aug 03 '24 06:08 fjames86

I'll try that next week. Thank you!

dertuxmalwieder avatar Aug 04 '24 13:08 dertuxmalwieder

Indeed, using the bitmap/icon data as defvars and calling them from a defun during +wm-paint+ works. :-)

dertuxmalwieder avatar Aug 05 '24 08:08 dertuxmalwieder