Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1355  / 1 Year ago, fri, march 10, 2023, 7:43:32

I have been doing front and back end web programming for over a year now, and now I am trying to learn 2D game programming in Java. Based on various sources on the web as well as one from my friend who is an experienced game developer, this is a typical setup:





Window.java | Window setup class



Game.java | Main game class





But when I attempt to run the Game class, the frame opens and then freezes, the only thing I have control of is my mouse, nothing else. I know the problem occurs in the render method, because the program runs fine when that method has an empty body.



I copied the code exactly from the tutorial in which it runs fine, and my friend who sent me an almost identical version which works on his computer, causes the same freeze for me. In both the tutorial and my friend's testing, the operating system is Windows, which causes me to believe that this is strictly an Ubuntu/Linux problem.



I have an Intel i7 3.4gHZ processor, and 8 gigs of RAM, so processing and memory shouldn't be the issue here. Any ideas of what is going on? I know that this is more of a programming question, but the fact that the problem seems to be Ubuntu-specific leads me to post it here.



EDIT



I've isolated the problem to one line in the Game class: bs.show(). For some reason, it is freezing as soon as I try to show the buffer strategy. If I create the buffer strategy with 1 buffer, it works fine, with anything greater than 1, it freezes.



When it froze the most recent time, I opened a virtual desktop and ran top, the weirdest thing is that Java was taking up less than 2% CPU and 6% memory. That just doesn't add up. I really need some help for what is going on here, I've gone about as far as I can go and I don't want to force any more restarts on my machine.


More From » 14.04

 Answers
2

I'm having the same problem when running your code. It seems to be a performance issue. To fix it, addSystem.setProperty("sun.java2d.opengl", "true"); to the main method in Game.java like this,



 public static void main(String args[]) {
System.setProperty("sun.java2d.opengl", "true");
new Game();
}


Hope this helps!


[#22503] Sunday, March 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byishted

Total Points: 469
Total Questions: 113
Total Answers: 113

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;