I have a game which uses FPSAnimator for the game loop. The game runs perfectly fine for about a minute, and then becomes choppy. Sometimes, also for seemingly no reason, it might snap back to normal speed. Now, I'm just an amateur programmer, and not great at all with debugging. I can't really rule out a memory leak, and Netbeans is helping me sort that out, but when debugging comes into play I get stupid.

Does anyone have any thoughts? I don't know what to post here (as far as code goes), so let me know please.

Are you creating textures every frame, or reading from disk every frame? Otherwise a likely source of choppiness is creating a lot (and I mean a lot) of objects that need to get garbage collected.

Another possibility is that you're using v-sync and it slows down a little bit java side, but enough to drop an entire frame refresh on the monitor (i.e. 60 fps drops to 30 fps, even if you could get 45-55 fps without v-sync).

No, it's just the one texture. Not reading from the disk either. I can't imagine that too many objects are being created... That's one of the things the Netbeans profilers are good for. I do use vsync, but I just tried turning it off and tweaking the fps desired and the result was horrible. It was choppy and crappy from the start. At least with the original setup the game ran smoothly for a little while and then turned crappy. I'm stumped.

It doesn't look like your graphics code should be slow at all, certainly nothing that would drop you less than 60fps and make it stutter. You are doing collision detection in your update method, and that might be expensive and slow (I don't know how many things there are, or how fancy you're getting), so I'd try to time that method.

You can add some poor-man's profiling by wrapping calls to a method with something like:

Dude.... I never program when I'm drunk (like I am now). However you're awesome. I will try that. I should say though, that the collision method is not the problem. It takes two ints. Those ints are coordinates in a 2d array. The method returns a simple boolean. I never paid attention in class but that should take a constant amount of time (and not much at theat). Collision aint no problem.

What the hell is up with my code? This is killing me. My pre-VBO code has this problem too.

OKAY. Maybe I should code while drunk. Another post giuy said to release the VBO bindings when done with them. I did that, and ran the program. I let it sit for two minutes, after which point it usually stutters. IT DID NOT. I will do more testing but I am hopeful.

If all you're doing is checking the player's position in an array, to see if it's in a bad spot, then yes the collision detection will be constant time. Usually collision detection in games checks the player with everything (ie in physics) and that can be done in a lot of stupid ways but it doesn't sound like your collision detection is doing that type of work.

Not really sure about the releasing of VBOs. It's still a best practice to release VBOs so keep that code in, but in my experience I don't every remember having that be a speedup. It's possible that your graphics card is doing something weird and gets in an unoptimized state if there is a VBO bound and you disable the vertex/texture client states. But that's all conjecture.

Not really sure about the releasing of VBOs. It's still a best practice to release VBOs so keep that code in, but in my experience I don't every remember having that be a speedup. It's possible that your graphics card is doing something weird and gets in an unoptimized state if there is a VBO bound and you disable the vertex/texture client states. But that's all conjecture.

Well I'm still drunk so I won't do any more testing (I can't trust the results in this state) but I think the results were very promising with my fix.

EDIT - No, that did not solve anything. The game still started stuttering.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org