Using Canvas object

I’ve been playing with some basic animation code lately, and put together a small demo program for running in windowed mode. I’m using Canvas/BufferStrategy, and am having horrible results. About once every second I get a ~300ms lag.
It certainly has nothing to do with gc (I can see that with the -verbose:gc option), and using the -Xrunhprof:cpu=samples option, I get:

1 66.47% 66.47% 666 81 sun.awt.motif.MComponentPeer.swapBuffers
2 16.47% 82.93% 165 31 sun.awt.motif.MToolkit.run

Any clues as to what’s going on? My animation loop is very standard. Also, I’m working on Linux and have a new nVidia card.

These problems are causing me to think about manually doing double-buffering using the standard techniques. For windowed-only apps, is this a better solution?

[quote]Why not use Thread.dumpStack()? It’s designed exactly for what you seem to need…
[/quote]
Also, as I just belatedly realised, that method hasn’t been upgraded to support the new 1.4 way of doing stack-traces - i.e. programmatic access. In most of the development I do, System.out and System.err are NOT safe places to be outputting stuff (you can’t guarantee they are being saved to disk, you can’t necessarily divert them over a network, etc).

So my logging library does everything with the programmatic access, with the added benefit of doing nice reformatting, highlighting of the most relevant code (HTML output: select the style based on the package of each frame in the trace; makes it easier to differentiate between 3rd party, standard library, and your own code when looking at massive stack traces :)) etc.

But I think you have to have a Throwable for that at the moment ?

I do not use Swing components, its not available on all PC’s, i use only 1.1 components, and i am really happy with AWT lightweight components, for applications i use newest jdk ( i can supply them on CD’s so no problem even if the jdk is 500MB big )

But for RT games there is no need for swing components, i have my own controls, maybe swing is nice for money orientated apps for stock charts etc, but thats nothing for me, zzZZZZZzzzzz

[quote]I’ve been playing with some basic animation code lately, and put together a small demo program for running in windowed mode. I’m using Canvas/BufferStrategy, and am having horrible results. About once every second I get a ~300ms lag.
It certainly has nothing to do with gc (I can see that with the -verbose:gc option), and using the -Xrunhprof:cpu=samples option, I get:
[/quote]
This is probably a red herring, but a long time ago I had similar problems that in the end turned out to be that I was accidentally reloading the sprites from disk lots of times, instead of just once and caching them (one line mistake!). I also had similar problems, but only on windows IIRC, that seemed to be bad event handling. When I removed all the keylistener mouselistener code etc - as an experiment - it went away.

I really feel for you on the profiling problem - in some graphical games on linux it seems you just get 60% - 90% of your time spent in a monolithic set of Toolkit classes, with no further breakdown of WTF is happening :(.

blahblah are u using multiple threads in your program ?

srlindemann, it all depends on the kind of rendering you’re doing.

On linux currently we’re using Pixmaps for storing managed and volatile images and double-buffer extension for buffer-flipping, so it should work pretty fast if the x server supports the extension. But, as usual, if you’re using lot of transparency/compositing, antialiasing, etc, it’ll be slow because X11 doesn’t support these operations, so we must use our software loops.

Run your test app with -Dsun.java2d.trace=count, and post the output - it’ll help to determine what primitives you’re using.

[quote]blahblah are u using multiple threads in your program ?
[/quote]
In my current one, yes. If you mean the one where I had the funny pauses, yes of course I was - because using the AWT events imposes that on you (one of the oft-cited reasons for using LWJGL, IIRC), and I can’t remember how things went with invokeLater etc…

I have had “fun” in the past with the Windows Scheduler (which sucked), but on the whole no threading problems (except where caused by threads inside the JVM that I had no control over).

Does this cover what you wanted to know?

hm really strange blahblah, i noticed this little pauses in some programs. if it is caused by a thread from the jaba framework then we are in big trouble