| Summary: | [FORMS] FormToolkit#setBackground disposes Colors which are still in use | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Remo Loetscher <remo.loetscher> | ||||||||
| Component: | User Assistance | Assignee: | Chris Goldthorpe <cgold> | ||||||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | cgold, pwebster, remo.loetscher, remy.suen | ||||||||
| Version: | 3.6.2 | ||||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows Vista | ||||||||||
| Whiteboard: | stalebug | ||||||||||
| Attachments: |
|
||||||||||
|
Description
Remo Loetscher
Created attachment 198249 [details]
Force the dispose color bug
Importance set new from "major" to "normal". Workaround found: If a formtoolkit with an own FormColor is used the background can be set/changed on that toolkit. See attached file "Force the dispose color bug (Workaround)" -> Button "FormToolkit(with own FormColors)#setBackground(Color)". Created attachment 198459 [details]
Force the dispose color bug (Workaround)
I was able to reproduce the bug, I will look into it. The bug occurs only if on the same FormToolkit is used for header decoration AND background change: Snippet 1 - this will fail: FormToolkit toolkit_default = new FormToolkit(shell.getDisplay()); toolkit_default.decorateFormHeading(<form>); toolkit_default.setBackground(<color>); toolkit_default.createXYZ(); Snippet 2 - this will work: FormToolkit toolkit_default = new FormToolkit(shell.getDisplay()); FormToolkit tollkit_with_new_background = new FormToolkit(shell.getDisplay()); toolkit_default.decorateFormHeading(<form>); tollkit_with_new_background.setBackground(<color>); tollkit_with_new_background.createXYZ(); Note that in the second snippet the decoration is not done by the toolkit on which the background color was changed. btw: Using a new FormColor object seems to have no effect on that... The "reason" for this bug is in the FormToolkit#decorateFormHeading() which will "force" the FormColor by calling FormColor#getColor() to run initializeFormHeaderColors() and initializeSectionToolBarColors(). If the FormColor is "initialized" in that way a call FormColor#setBackground() will dispose the colors in the FormColor#updateFormHeaderColors() Method. In Snippet 2 the FormColor is not yet initialized, so the method FormColor#updateFormHeaderColors() does nothing. If no FormToolkit#decorateFormHeading() method is called in any way, there is no problem. I adapted the snippet which is attached to this bug. Created attachment 198509 [details]
Force the dispose color bug (Workaround)
This is what I think is happening. Each FormToolkit has a FormColors object which is used to store the colors used in a form, these colors are created and owned by the FormColors object and are derived from the foreground and background colors using blending rules. If the foreground or background color changes new colors are created and the old ones disposed. What should instead happen is that the colors are not disposed until the FormToolit is disposed. My only concern with deferring the disposal would be that a program which contained a FormToolkit object with a long lifetime would consume more memory every time a call to setBackround() is made. It sounds as though you have a workaround and this bug is not blocking you - is that correct? (In reply to comment #7) > It sounds as though you have a workaround and this bug is not blocking you - is that correct? Yes, the bug is not blocking anymore. The attached workaround works for me. But nevertheless the "undocumented dependency" between the function call "FormToolkit#decorateFormHeading()" and "FormToolkit#setBackground()" should be fixed/documented in a way. The problem occurs only if decorateFormHeading() and setBackground is called in that order on the same toolkit instance. So possible fixes could be: - do not dispose colors if the form header was decorated and setBackground is called -> use the "old" colors -> setting background has no impact in the blending rules for headers and sections - allow to set/change background color only at a specific point -> before the first decorateFormHeading() call; this way setting the background works - Document the "dependency" in the javadoc [- resetting references to colors in sections and form header after setBackground() was called] This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |