Results 1 to 16 of 16
Thread: Repaint suddenly stops drawing
- 11-02-2013, 02:56 PM #1
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Repaint suddenly stops drawing
Problem: I have a game loop running in my project and sometimes it just stops rendering.
Code:
Java Code:while (running) { if (timerfps.hasTimeGone()) { repaint(); System.out.println("Rendering"); } System.out.println("Running"); }
the timerfps is my own timers set to 60 ticks / seconds.
Is there a reason why it just stops calling the method?
- 11-02-2013, 03:18 PM #2
Re: Repaint suddenly stops drawing
If the timerfps.hasTimeGone() method stops returning true, the repaint() method won't be called. If "Rendering" is printed, then the repaint() method would have been called.
Do you have a println() call in the paintComponent() method that is called unconditionally? Does it stop printing?
Can you make a small, complete program that compiles, executes and shows the problem?If you don't understand my response, don't ignore it, ask a question.
- 11-02-2013, 03:28 PM #3
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Re: Repaint suddenly stops drawing
It keeps printing "Rendering" every 60 / second -> timerfps.hasTimerGone() returns true every 60 / second.
I have a println() in the paintComponent method that stops printing after a while (when the drawing to the panel stops).
The problem with creating a SSCCE is that it has never happened before and seems to be totally random. So I can't really create one.
- 11-02-2013, 03:35 PM #4
Re: Repaint suddenly stops drawing
Sorry, I have no suggestions. Non-repeatable bugs are really hard to find and fix.
If you don't understand my response, don't ignore it, ask a question.
- 11-02-2013, 03:42 PM #5
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Repaint suddenly stops drawing
How large is your application? Can you show the paintComponent method? Are you catching any exceptions but not printing them?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 11-02-2013, 03:53 PM #6
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Re: Repaint suddenly stops drawing
The project is rather large. I've been working on it for like a month now. Coding maybe 3-6 hours a day.
Java Code:public void paintComponent(Graphics g) { System.out.println("PaintComponent is drawing"); fps++; super.paintComponent(g); render(); imgh.draw(g); imgh.resetImages(); }
I'm not catching any errors in the render methods or getting any of that sort.
- 11-02-2013, 03:57 PM #7
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Repaint suddenly stops drawing
Are you certain that your program is not doing something differently later on that might not be changing the way you expect. Also, why are you automatically rendering every 60th of a second instead of when something needs to really be repainted?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 11-02-2013, 04:02 PM #8
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Re: Repaint suddenly stops drawing
Now that I've looked into my code, I do have a while loop that might the the problem.
Java Code:while(useLayer);
- 11-02-2013, 04:05 PM #9
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
- 11-02-2013, 04:15 PM #10
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Repaint suddenly stops drawing
If you are using multiple threads, it could be a problem. Is useLayer marked as volatile (still may not solve the problem)? Some compilers will change some
code like this:
Java Code:while (useLayer);
Java Code:if (useLayer) { while(true); }
block (the details of which cannot be explained here).
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 11-02-2013, 04:21 PM #11
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Re: Repaint suddenly stops drawing
No, it's not volatile or any of that sort, but changing it to that seemed to fix it or at least made it less frequent. Can't say for sure yet but hopefully it worked.
Thanks a lot!
- 11-02-2013, 04:25 PM #12
Re: Repaint suddenly stops drawing
How does the app handle all the printlns? If "Rendering", "Running" and"PaintComponent is drawing" are being printed 60 times a second that creates a lot of output.
If you don't understand my response, don't ignore it, ask a question.
- 11-02-2013, 04:29 PM #13
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Repaint suddenly stops drawing
You're welcome! I hope it works. BTW, you should refrain from using tight loops to enter wait states. It would be better to to use a sleep within a loop. Or if possible, use the wait/notify capability of the Java thread architecture. That's what it's there for. You might want to investigate the java.util.concurrent package to see if anything there can support your application.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 11-02-2013, 09:50 PM #14
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
- 11-02-2013, 10:04 PM #15
Re: Repaint suddenly stops drawing
Yes, I understood that. What I was wondering about is what happens to all the lines that are printed when you are debugging. Does your console hold all the lines so you can look back through all of them to see when anything could have changed when the code was executing?
If you don't understand my response, don't ignore it, ask a question.
- 11-06-2013, 06:57 PM #16
Member
- Join Date
- Mar 2012
- Location
- Sweden
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
please help me my myeclipse is closing suddenly
By javastuden in forum EclipseReplies: 0Last Post: 01-21-2010, 05:43 AM -
Java suddenly not working. Red X
By kd1516 in forum New To JavaReplies: 3Last Post: 10-23-2008, 06:23 AM -
[SOLVED] Problem in Drawing(Repaint)
By Preethi in forum New To JavaReplies: 2Last Post: 07-16-2008, 08:28 AM -
Bouncing Ball Just Suddenly Stops Mid Bounce
By adlb1300 in forum Java 2DReplies: 1Last Post: 12-03-2007, 03:58 PM
Bookmarks