• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Strange sudden shear/flip bug in java graphics when too many objects are rotating on the screen  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the early seconds when I launched my program everything was fine but as time went by, my main Object(the animal(pokemon) in the screenshot) got this kind of strange bug where the object image sheared/flipped for no reason. I have this program that rotates 25 sub objects(gray blob in the screenshot) and a main object that can be move and rotated by the user.

Here's my screenshot:

started to launch


After 90 seconds(approx.)


When I removed the rotate code of sub objects, I didn't get the bug.

sub objects no rotation


Here's my transform code on my main and sub objects

I already commented the rotate code







I tried to change this to paintComponent and the problem still persisted.
       

 
Elya Matsunomi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any suggestion why this bug happens? I hope someone can help me on this as this bug is very challenging to fix for me because this bug randomly happens. I'll try to find a way to solve this and post my solution if I fix it.
 
Elya Matsunomi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed it, sort of. I don't know if I fix this bug for good, but what I did to fix the bug was to create another BufferedImage for the main object. So, Sub objects group has their own bufferedimage and the main object has its own bufferedimage. As of now, my image didn't flip/shear, but I'm not really sure if the bug on my program is fixed because this bug can appear abrupt and random. I don't know the cause of this bug but base on my assumption, a graphic transformation may mess up if there's too much transform operation happening in the graphic.
 
Elya Matsunomi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found another simple fix to this bug. Just reorder the codes in the paint() method

From this:



To this:



So, I draw the sub and main object first then draw the status information.

And this is the result:



I assume the reason why this bug happens is because paint() is slower than the timer. So, the timer updates the objects transform values in the program and paint() draws the transformation of objects. In my assumption, timer is faster than paint(), so, the timer might update the objects transform values while paint() is still drawing the objects. So, the transform values in Graphics2D gets scrambled and produces unexpected result.  
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!