Archive for August, 2013

TWICImage Access Violation in Delphi 2010 on second usage

Sunday, August 11th, 2013

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