TCustomBitmap UnshareImage and SetSize are faulty
Original Reporter info from Mantis: bruce
-
Reporter name: Bruce Tulloch
Original Reporter info from Mantis: bruce
- Reporter name: Bruce Tulloch
Description:
If UnshareImage is called without its CopyContent argument asserted
the image Description attribute is lost. This seems like undesirable
behaviour; why does unsharing an image loose this information?
But it's worse than that. Unsharing an image reassigns the bitmap's
FSharedImage attribute but the name of this method and the available
LCL documentation makes no mention of this fact (at present).
This leads to subtle bugs like one in introduced in TCustomBitmap
SetSize (in SVN r15510) where FSharedImage is assigned to a local
variable SCB before the call to UnshareImage(False) and then used
(erroneously) afterwards (ie, still referring to the old image).
The combination of these bugs causes all sorts of subtle problems
when a bitmap is resized. I have created the patch below against
r19078 (to fix both bugs). It should also apply successfully to
r19567 (the SVN head as of now).
Testing with an in-house application here which uses several layers
of bitmaps driving a TPaintBox which provides their size properties
now works correctly when the application is resized. Prior to this
patch various bitmaps would not be resized correctly or ended up
with invalid Width or Height properties.
This patch makes the smallest change possible to fix the problems
identified to avoid introducing unintended side-effects but it may
not be the most elegant solution. I have also checked elsewhere in
the code where UnshareImage is used and SetSize looks like the only
place where this causes a problem.
Mantis conversion info:
- Mantis ID: 13556
- OS: Debian
- OS Build: Lenny
- Build: r19078
- Platform: Linux
- Version: 0.9.27 (SVN)
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 20339 (#73234daa)
- Target version: 0.9.28