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

Bug 124075

Summary: restoreState error
Product: [Tools] GEF Reporter: Yang Liu <yliu000>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: major    
Priority: P3    
Version: 3.1.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Yang Liu CLA 2006-01-17 00:46:44 EST
In org.eclipse.draw2d.SWTGraphics, 
in my understanding, the graphics state is saved in two places: the underly GC (state.affineMatrix) and the other fields in state (such as bgColor, bgPattern).

So when restore state, need to restore both.

In current implementation (3.1.1), the restoreState() method is something like this:
setAffineMatrix(s.affineMatrix);
...
setBackgroundPattern(s.bgPattern);
...

So it restore the affineMatrix first. But in setBackgroundPattern(), if the pattern is not null, it will futher do the following:
setBackgroundPattern
    initTransform
        new Transform()
        gc.setTransform(transform)

Thus change the underlying matrix in the GC again!

So after restoreState(), the underlying matrix may not revert back to old state!

I was trying a fix to move the "setAffineMatrix(s.affineMatrix)" statement to the end of "restoreState()" method. It seem to work fine.
Comment 1 Yang Liu CLA 2006-01-17 01:06:14 EST
hmm, possible of the real cause of the problem is:

public void setBackgroundPattern(Pattern pattern) {
	currentState.graphicHints |= ADVANCED_GRAPHICS_MASK;
	if (currentState.fgPattern == pattern)
                         ^^
		return;
	currentState.bgPattern = pattern;

	if (pattern != null) {
		initTransform(true);
		gc.setBackgroundPattern(pattern);
	}
}

It should be bgPattern!
Comment 2 Randy Hudson CLA 2006-01-17 09:53:48 EST
This was fixed already in the HEAD stream, aka 3.2.