Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328588

Summary: Pattern is not disposed after usage in SWTGraphics class
Product: [Tools] GEF Reporter: Vijay Raj <vijay.rajonline>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: critical    
Priority: P3 CC: aboyko, hudsonr, nyssen
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Vijay Raj CLA 2010-10-25 06:56:15 EDT
Build Identifier: I20091030-1201

The setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2) method creates a Pattern instance this pattern instance is never disposed. This causes operating system resourse leak and subsequent crash..
For more info please refer to following forum post 
http://www.eclipse.org/forums/index.php?t=msg&th=198946&start=0&S=9b5f15a2375820e01222631713f587e3

Reproducible: Always

Steps to Reproduce:
http://www.eclipse.org/forums/index.php?t=msg&th=198946&start=0&S=9b5f15a2375820e01222631713f587e3
Comment 1 Randy Hudson CLA 2010-10-25 10:17:03 EDT
Vijay, on which class are you calling that method?
Comment 2 Vijay Raj CLA 2010-10-25 12:40:01 EDT
(In reply to comment #1)
> Vijay, on which class are you calling that method?

Either ScaledGraphics or SWTGraphics instance which ever comes in IFigure.paintFigure(Graphics graphics) method accordingly...


ScaledGraphics.setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2) method delegates the call to SWTGraphics.setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2)

hence you can say that the problem is in SWTGraphics.setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2) method...
Comment 3 Alex Boyko CLA 2010-10-25 13:19:46 EDT
Vijay, think this might be an invalid bug.

There is only setBackgroundPattern(Pattern) methiods on Graphics class and SWTGraphics, which means is up to the client to create and dispose patterns. Same as colors, fonts, images and anything else requiring platform resource.
Comment 4 Vijay Raj CLA 2010-10-26 00:08:24 EDT
(In reply to comment #3)
> Vijay, think this might be an invalid bug.
> 
> There is only setBackgroundPattern(Pattern) methiods on Graphics class and
> SWTGraphics, which means is up to the client to create and dispose patterns.
> Same as colors, fonts, images and anything else requiring platform resource.

Thats correct in case of SWTGraphics.setBackgroundPattern(Pattern) or ScaledGraphics.setBackgroundPattern(Pattern) the user has to create the Pattern and he alone is responsible for disposing it...

But in ScaledGraphics we can not use setBackgroundPattern(Pattern) ,because we have to compensate for scaling, instead we should use setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2) which compensates for scaling

public void setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2)
    {
        int x1s = (int) (Math.floor(x1 * zoom + fractionalX));
        int y1s = (int) (Math.floor(y1 * zoom + fractionalY));
        int x2s = (int) (Math.floor(x2 * zoom + fractionalX));
        int y2s = (int) (Math.floor(y2 * zoom + fractionalY));
        graphics.setBackgroundPattern(new Pattern(device, x1s, y1s, x2s, y2s,               color1, color2));
    } 

But as you can see from above code it creates a Pattern class which will never get disposed since this method calls the actual setBackgroundPattern(Pattern) method, which assumes that the pattern instance has been sent by the user and he is responsible for the disposal!!!!
Comment 5 Vijay Raj CLA 2010-10-26 01:19:53 EDT
(In reply to comment #3)
> Vijay, think this might be an invalid bug.
> 
> There is only setBackgroundPattern(Pattern) methiods on Graphics class and
> SWTGraphics, which means is up to the client to create and dispose patterns.
> Same as colors, fonts, images and anything else requiring platform resource.

Same is the case (In reply to comment #4)
> (In reply to comment #3)
> > Vijay, think this might be an invalid bug.
> > 
> > There is only setBackgroundPattern(Pattern) methiods on Graphics class and
> > SWTGraphics, which means is up to the client to create and dispose patterns.
> > Same as colors, fonts, images and anything else requiring platform resource.
> 
> Thats correct in case of SWTGraphics.setBackgroundPattern(Pattern) or
> ScaledGraphics.setBackgroundPattern(Pattern) the user has to create the Pattern
> and he alone is responsible for disposing it...
> 
> But in ScaledGraphics we can not use setBackgroundPattern(Pattern) ,because we
> have to compensate for scaling, instead we should use
> setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color
> color1, Color color2) which compensates for scaling
> 
> public void setBackgroundPattern(Device device, int x1, int y1, int x2, int y2,
> Color color1, Color color2)
>     {
>         int x1s = (int) (Math.floor(x1 * zoom + fractionalX));
>         int y1s = (int) (Math.floor(y1 * zoom + fractionalY));
>         int x2s = (int) (Math.floor(x2 * zoom + fractionalX));
>         int y2s = (int) (Math.floor(y2 * zoom + fractionalY));
>         graphics.setBackgroundPattern(new Pattern(device, x1s, y1s, x2s, y2s,  
>             color1, color2));
>     } 
> 
> But as you can see from above code it creates a Pattern class which will never
> get disposed since this method calls the actual setBackgroundPattern(Pattern)
> method, which assumes that the pattern instance has been sent by the user and
> he is responsible for the disposal!!!!

Same is the case with SWTGraphics.setBackgroundPattern(Device device, int x1, int y1, int x2, int y2, Color color1, Color color2)
Comment 6 Randy Hudson CLA 2010-10-26 12:26:05 EDT
(In reply to comment #5)
> Same is the case with SWTGraphics.setBackgroundPattern(Device device, int x1,
> int y1, int x2, int y2, Color color1, Color color2)

There is no such method, see for yourself:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/SWTGraphics.java?view=markup&root=Tools_Project
Comment 7 Randy Hudson CLA 2010-10-26 12:27:26 EDT
If you want your patterns to scale, you shouldn't be using ScaledGraphics.  SWTGraphics also support scaling, but in a different way that causes patterns to scale for "free".
Comment 8 Vijay Raj CLA 2010-10-27 00:52:17 EDT
(In reply to comment #7)
> If you want your patterns to scale, you shouldn't be using ScaledGraphics. 
> SWTGraphics also support scaling, but in a different way that causes patterns
> to scale for "free".

Sorry Randy ,my mistake ,please make it an invalid bug...
some confusion between my version of draw2d and the actual draw2d...

(yes thats a real pain, keeping my own version but what to do i needed org.eclipse.gmf.runtime.draw2d.ui classes without any gmf dependencies and my own requirements)

And sorry again for wasting your valuable time...
Comment 9 Alexander Nyßen CLA 2010-10-27 07:00:30 EDT
Resoving invalid due to last comment.