JDK-4200808 : jdk1.2 paint() fails with too many rectangle fills
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_95
  • CPU: generic
  • Submitted: 1999-01-05
  • Updated: 2001-11-16
  • Resolved: 2001-11-16
Related Reports
Relates :  
Description

Name: krT82822			Date: 01/05/99


Original user synopsis:  "jdk1.2 paint() fails with too many rectange fills"

The following program creates a borderless box with a gradient
fill.  The program should be compiled under jdk1.2 and involked 
by typing 'java Test 640 480'.  The size of the box can be changed
by specifing a different x and y as arguments.  Depressing the 
keys r,g,b,y,m,c,w,k will change the color to red, green, blue,
yellow, magenta, cyan, white and black respectively.  Using the
jdk1.2 enviornment depressing the keys r,g,b,y,m all work.  When
c is depressed the fill starts but stops about a sixth of the way 
across the screen. The problem is not associated with the color
cyan but the fact that it is the 6th color depressed.  It appears
as though it is running out of memory as icons in the editor
which I have open sometimes turn black or go blank at the same
time that the fill stops.  If the same class is run with the
jdk1.1.6 enviornment without recompiling it works fine.
I saw this same thing on earlier versions of the jdk1.1.1 or so 
then it was fixed on newer versions and now it is back again.

When this happens there are no error messages.

Since the compiled class works with jdk1.1.6 and not 1.2 I think
it is something in the run time lib or the java.exe which is
causing the problem.

I tried to force garbage collections but that didn't help.

This is occurring on the Win95 implimentation.

here is the code: 

//------------Test.java------------

import java.awt.*;
import java.awt.event.*;

public class Test extends Panel
{int cc;
 boolean solid=false;
 FullScreen fs;

  public Test(Window w, int x, int y)
   {w.setBounds(0,0,x,y);
    w.setVisible(true);
    w.addKeyListener(new TestKey());
    this.setSize(x,y);
    w.add("Center",this);
    cc=1;
    fs=new FullScreen(0,0,x,y,cc);
    setVisible(true);
    repaint();
   }

 class TestKey extends KeyAdapter
   {public void keyTyped(KeyEvent e)
     {int x=e.getKeyChar();
      switch (x)
        {case       'q' : System.exit(0);         break;
         case       'w' : cc=0;  fs.setColor(cc); break;         // Set fcolor to white
         case       'r' : cc=1;  fs.setColor(cc); break;         // Set fcolor to red
         case       'g' : cc=2;  fs.setColor(cc); break;         // Set fcolor to green
         case       'b' : cc=3;  fs.setColor(cc); break;         // Set fcolor to blue
         case       'y' : cc=4;  fs.setColor(cc); break;         // Set fcolor to yellow
         case       'm' : cc=5;  fs.setColor(cc); break;         // Set fcolor to magenta
         case       'c' : cc=6;  fs.setColor(cc); break;         // Set fcolor to cyan
         case       'k' : cc=7;  fs.setColor(cc); break;         // Set fcolor to black
         case       'l' : fs.rotate();  break;  // Toggle line horz - vert
         case       'f' : solid=!solid; break;
        }
      repaint();
     }
   }

  public void paint(Graphics g)
   {if (solid) fs.showSolid(g);
    else fs.show(g);
    System.gc();
   }

 public static void main(String args[])
   {int x=java.lang.Integer.parseInt(args[0]);
    int y=java.lang.Integer.parseInt(args[1]);
    Window nw=new Window(new Frame()); 
    new Test(nw,x,y);
   }

}


//------------------FullScreen.java------------

import java.awt.*;

public class FullScreen
{int    x,y;           // start location
 int    w,h;           // width and height
 int    fmin,fmax;     // foreground min and max
 int    vrot;          // rotate position
 int    cc;            // current color

  public FullScreen(int x,int y,int w,int h,int cc)
    {this.x=x;
     this.y=y;
     this.w=w;
     this.h=h;
     fmin=0;
     fmax=255;
     vrot=0;
     this.cc=cc;
    }

   public void  setColor(int cc)
    {this.cc=cc;
    }

   public Color setLevel(int v)
    {Color x=Color.red;
     switch (cc)
       {case 0 : x=new Color(v,v,v); break; //white
        case 1 : x=new Color(v,0,0); break; //red
        case 2 : x=new Color(0,v,0); break; //green
        case 3 : x=new Color(0,0,v); break; //blue
        case 4 : x=new Color(v,v,0); break; //yellow
        case 5 : x=new Color(v,0,v); break; //magenta
        case 6 : x=new Color(0,v,v); break; //cyan
        case 7 : x=new Color(0,0,0); break; //black
       }
     return x;
    }

  public void rotate()
    {vrot=(vrot=vrot+1)%4;
     int temp;
     switch (vrot)
       {case 0 : temp=fmax;
                 fmax=fmin;
                 fmin=temp;
                 break;
        case 1 : break;
        case 2 : temp=fmax;
                 fmax=fmin;
                 fmin=temp;
                 break;
        case 3 : break;
       }
     }  

  public void showSolid(Graphics g)
    {g.setColor(setLevel(fmax));
     g.fillRect(x,y,w,h);
    }

  public void show(Graphics g)
    {double xstep;
     if ((vrot==0)||(vrot==2))
      {if (fmax > fmin)
         {xstep=(double)(w*1.0/(fmax-fmin));
          for (int i=fmin; i<fmax ;i++ )
            {g.setColor(setLevel(i));
             g.fillRect((int)((i-fmin)*xstep),0,(int)xstep+1,h);
            }
         }
       else if (fmax < fmin)
         {xstep=(double)(w*1.0/(fmin-fmax));
          for (int i=fmin; i>fmax ;i-- )
            {g.setColor(setLevel(i));
             g.fillRect((int)((fmin-i)*xstep),0,(int)xstep+1,h);
            }
         }
       else
         {g.setColor(setLevel(fmax));
          g.fillRect(x,y,w,h);
         }
      }
     else
      {if (fmax > fmin)
         {xstep=(double)(h*1.0/(fmax-fmin));
          for (int i=fmin; i<fmax ;i++ )
            {g.setColor(setLevel(i));
             g.fillRect(0,(int)((i-fmin)*xstep),w,(int)xstep+1);
            }
         }
       else if (fmax < fmin)
         {xstep=(double)(h*1.0/(fmin-fmax));
          for (int i=fmin; i>fmax ;i-- )
            {g.setColor(setLevel(i));
             g.fillRect(0,(int)((fmin-i)*xstep),w,(int)xstep+1);
            }
         }
       else
         {g.setColor(setLevel(fmax));
          g.fillRect(x,y,w,h);
         }
      }
    }

}
(Review ID: 48173)
======================================================================

Comments
EVALUATION Windows95 only has 5 available DCs. It sounds like we were using up all five, which caused the application to fail on the 6th selection. We rearchitected the graphics stuff to stop using CS_OWNDC in 1.3, so this problem has been solved (see bugid 4045781). Can't test right now because of focus bugs (merlin beta build 48). eric.hawkes@eng 2001-01-21 ================================ First off a java.awt.Window without a focusable component cannot gain focus, so adding a KeyListener to it will not work. Instead the listener can be added to the parent Frame. I have attached the revised Test.java and unchanged FullScreen.java Once this is done the program works fine with Merlin B86 with Solaris or Win32. ###@###.### 2001-11-16
16-11-2001