mudFlap75's picture

Examples "Busy Waits" on MacOs X


I've tried "all" the examples on my mac, and at a first glans it seems like they "hangs" the process.
After some investigation, I noticed that the code "busy waits" in aglSwapBuffers(), leaving almost no time left for the os to work with.

Is this a bug? aglSwapBuffers() is supposted to wait for the next vbl, but it freezes out the Os from the process in this case.
I guess I can put all the rendering on it's on thread, but is that the intended way of doing it?

I'm using: OS-X-SnowLP, macbook-pro/dual core/nvidia

Best regards


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Starting with the next OpenTK version, examples should no longer hog the CPU.

aglSwapBuffers() is part of the Mac OpenGL stack, there's no way to avoid it or modify its behavior. Many drivers will sleep in SwapBuffers() (or the next OpenGL call after SwapBuffers()) when vsync is enabled - worth a try.

If that doesn't work, you will need to insert a call to Thread.Sleep(ms), where ms = 1 or higher. The best place to do that is right after your SwapBuffers() call.

mudFlap75's picture

I've played around a bit more. I'm not sure that it's SwapBuffers() that couses my problems. I've tried with Thread.Sleep() (with different values).
I'm new to Mac, Mono and OpenTK (used tao in the past). So i'm a little bit lost here as well :-)

This "Hog"-ing that you talk about, is it fixed in trunk? I'm using the 1.0.0-rc1 now.

the Fiddler's picture

The hogging is a feature, not a bug. By default, OpenTK runs as fast as it can unless you instruct it to sleep. (This is for GameWindow, GLControl is event-based and repaints only when necessary).

Can you give a few more details about the problem? When you say it hangs, are you referring to the OpenTK window, the OS, something else? (The window shouldn't hang even if CPU usage is high). Which versions of OpenTK and Mono are you using?

mudFlap75's picture

Sorry for being unclear.
The application is unresponsive. I can't move the window or click on any border-buttons. The mouse pointer shows "busy" when I hover over the window and I need to "kill" the application manually.
If a example uses moving graphics it seems to update the display though. I can see a cube spinning jn the "First shader" example.
I've tested with examples both that uses the GLControl and GameWindow.

I'm using:
openTK 1.0.0-rc1
mono 2.6.7

best regards

the Fiddler's picture

I can confirm this on Mono 2.8. Looking for the cause.

the Fiddler's picture

It is interesting that this affects the examples only. Stand-alone applications work fine.

I suspect this might be a threading issue or some other strange interaction between the examples launcher (WinForms) and OpenTK (GameWindow).