TWICImage Access Violation in Delphi 2010 on second usage

Been playing a bit with TWICImage in Delphi 2010 for a scaling thing and noticed there was an access violation when using it the “regular” way: create – use – free, create again – use – free
Googling didn’t explain it so I took a peak at the code and noticed it was using a singleton for a private member which would be destroyed once the reference count reached 0.

There is one valid workaround for it (well, more, but I’ll present one):
– define a global variable of type TWICImage.
– in the initialization section of the unit, create a TWICImage instance and assign it to this:
– in finalization, destroy it

var dummy : TWICImage = nil;

dummy := TWICImage.create;

No more AV since the refcount will always be 0 until the app closes.

Related posts

One Response to “TWICImage Access Violation in Delphi 2010 on second usage”

  1. Celal says:

    Thank you for the code. I was desperately looking for a solution and this worked perfectly.

Leave a Reply

This blog is kept spam free by WP-SpamFree.