• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 25
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.  
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic