• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

J2SE 1.5.0 fillPolygon method

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Java Folks,

Sorry to bother everyone, however, I am all out of ideas on a particular problem that I am having, and am hoping that someone can offer some advice. In short, my Java problem is as follows:

[1]
over the past year I have *successfully* implemented a "graphical geometry editor" using J2SE SDK 1.4.x. Again, everything worked fine under SDK 1.4.x, and life was good.

[2]
recently, however, I downloaded Sun's new J2SE SDK 1.5.0. I compiled my geometry editor successfully (without errors) against this new SDK 1.5.0, and then began using it. However, the following "fillPolygon" method of class Graphics is no longer working as it did before!

class: java.awt.Graphics
method: public void fillPolygon(Polygon p)

In short, any polygon that I render using this method is erroneously "offset" from where it **should** be rendered on my gui. In fact, here is an example of some code that exhibits this problem:

// I define a polygon using values x1,y1,x2,y2,
// which correctly defines a rectangle polygon
java.awt.Polygon squareMBRPoly = new java.awt.Polygon
(
new int [] {x1,x2,x2,x1},
new int [] {y1,y1,y2,y2},
4
);

// I set the graphics object color to an arbitrary value, in this case "orange"
g.setColor(Color.orange);

// I render the outline of the polygon via the "drawPolygon" method,
// which is **successful**, thus I know that my polygon definition
// is valid
g.drawPolygon(squareMBRPoly);

// next, I render a "filled" version of this **same**
// polygon object, however, it is INCORRECTLY offset
// when drawn to the gui. The polygon's shape is correct,
// it is simply been offset erroneously!!!
g.fillPolygon(squareMBRPoly);


[3]
Again, my same "geometry editor" source code, when compiled under J2SE SDK 1.4.x, runs correctly. I only get this problem when I switch to compiling and running my geometry editor under SDK 1.5.0. Offhand, I would say that there is a bug somewhere in the 1.5.0. SDK. This sounds ridiculous I know, however, I cannot think of any other reason for this runtime rendering behavior. FYI: I am SCJP/SCJD certified and have a BS degree in computer science & mathematics (just so you know that I am not a complete idiot. :-)


Any thoughts?


Best Regads,
John Dove
[email protected]
[email protected]
http://home.nycap.rr.com/jdove
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an entry in Sun's Java Bug Database pertaining to fillPolygon() in 1.5. It's an open bug. They say it's "possibly an X11 problem." So what platform are you running on? On Linux or Solaris, or on Windows?
 
John Dove
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

Thank you very much for the reply. I read the bug report that you had cited (i.e. Bug ID: 4937390), such that my comments are as follows:
Comments:

[1]
In regard to your question, the platform I am using for the development and testing of my geometry editor is as follows:

cpu type: intel pentium
cpu speed: 1.9 GHz
memory: 512MB
operating system: WindowsXP, HomeEdition, version 2002 (service pack 2)


[2]
In regard to the bug you cited (i.e. Bug ID: 4937390), it claimed that the polygon was rendered incorrectly (i.e. meaning its physical shape was not correct). In my case, and under SDK 1.5.0 only, my polygon's physical shape is rendered correctly, however, its position (i.e. the location on the screen where is is drawn) is erroneously "offset" from where it should be. Overall, my problem is different than bug 4937390, however, they might be linked. <shrug>

[3]
In the next day or two, I will write a very small sample application that attempts to demonstrate this behavior (i.e. in order to remove the concerned functionality from out of the editor that I have written, which is quite large (~4.0MB of source). I will post the results of my testing back here to the Java Ranch. In general, if I can consistently reproduce this behavior in a small isolate Java program, I will likely submit it to Sun as a bug

In any case, it is interesting to learn that there are confirmed problems in SDK 1.5.0 regarding the fillPolygon method. Ernest, if you or anyone else reading this forum thread happen to learn more about this problem, could you please post back? :-) Thanks.

Regards,
John Dove
[email protected]
[email protected]
http://home.nycap.rr.com/jdove

P.S. Ernest, I followed the link on your posting, which lead to a bit about the Jess book you wrote. Very cool. Btw, I am in the process of writing a Java video game programming book, such that the editor I am having a problem with (above) is a tool that I will ship with the book (if/when) the book ever actually gets finished. There is never enough time in the day.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Feel free to email me the source code of your "simplified" example. I will be glad to take a look at it and see if I can also reproduce the problem.

BTW, have you tried using the 1.5 compiler to generate 1.4 bytecode? Does this also produce the incorrect "offset" polygon?

Layne

p.s. You may also be interested in using UBB CODE tags when you post code here in the future. They will preserve the formatting in your code (assuming that you have good formatting habits after getting your BS ) and make it much easier for us to read.
[ July 20, 2005: Message edited by: Layne Lund ]
 
John Dove
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Layne,

>>> Feel free to email me the source code of your "simplified"
>>> example. I will be glad to take a look at it and see if
>>> I can also reproduce the problem.

Thank you for offering to help out! :-) I have not had a chance to create my trivial example for debugging purposes (wife, job and after work stuff keep me running in circles weekly). In the worst case scenario, I will have to "put off" doing this until this weekend. (Maybe I can sneak in a few lines of code while at work when my moss isn't around. ;-)



>>> BTW, have you tried using the 1.5 compiler to generate
>>> 1.4 bytecode? Does this also produce the incorrect
>>> "offset" polygon?

Not yet. I can look into this though.




>>> p.s. You may also be interested in using UBB CODE tags
>>> when you post code here in the future. They will
>>> preserve the formatting in your code (assuming that you
>>> have good formatting habits after getting your BS ) and
>>> make it much easier for us to read.

hehe Will do :-) What UBB codes do you usually employ (e.g. just bold-type the comments?)
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Dove:
What UBB codes do you usually employ (e.g. just bold-type the comments?)



Just use [ CODE][/CODE] tags around your formatted code, and UBB will preserve the indentation -- that's all.
 
John Dove
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I was successfully able to abstract the "polygon problem" I am seeing out of my larger program, and into the below smaller one (see below). I tried using the tags, so hopefully it will look ok. From what I am seeing, this "problem" is one of the following possibilities:

1. a bug in the J2SE 1.5.x SDK.
2. or a usability problem in the J2SE 1.5.x SDK. In other words its a WAD (works as designed) but it is NOT documented plainly enough for developers like myself to catch it.

Please let me know what you think. Thanks again for your help. If there is anything else that you need please let me know. I can send you the actually source code file via email if you like (i.e. I will need your addresses), as well as screen shots of what I am seeing at runtime under both 1.4.x and 1.5.0 SDK versions.

To that end, here is my little code piece, all sublime:

Thanks,
John

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I can confirm your observations; same thing happens for me (1.4.2_08 vs 1.5.0_02, both on Linux.)

I note (as I'm sure you did) that the size of the effect is related to the size of the offsets; if the offsets are two orders of magnitude smaller, the effect is not apparent. Sounds, therefore, like floating-point roundoff error.
 
John Dove
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

Thank you for the confirmation. At this point what do you suggest that I do? I have never submitted a "bug" to Sun. Since we have a reproducible test case here, what are the exact steps for notifying Sun about it?

Regards,
John Dove
[email protected]
http://home.nycap.rr.com/jdove
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's pretty straightforward, I think: go to http://bugs.sun.com/services/bugreport/index.jsp to get started.
 
John Dove
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I sucessfully logged it as a bug. Again, thank you for your "second pair of eyes" on this problem. I appreciate it.

Going back to SDK 1.4.x now... :-)

FYI, I got the following confirmation from Sun on the bug I posted:

************************************************
Your report has been assigned an internal review ID of: 494063

This review ID is NOT visible on on Sun Developer Network (SDN).

We greatly appreciate your interest in improving the quality
of Java(tm) Technology from Sun Microsystems.

Please be aware that the large volume of reports we receive
sometimes prevents us from responding individually to each
message.
 
reply
    Bookmark Topic Watch Topic
  • New Topic