veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.21k stars 221 forks source link

Example uses 100% CPU on macOS #500

Closed remko closed 2 years ago

remko commented 2 years ago

When compiling the example from the README on macOS (10.15.7, SDL2 2.0.16 from homebrew), the application goes to 100%. Printing the events that come from SDL_PollEvent, it doesn't seem that there are many events coming in (just what you would expect). Any clue what could be wrong, or how to figure out what's going wrong?

veeableful commented 2 years ago

Hi @remko, that should be because the loop doesn't have a delay so it would render as many times as it can. You could put a sdl.Delay(16) inside the for running {} loop to have it refresh at roughly 60 frames per second.

remko commented 2 years ago

Hi @veeableful Thanks! I was actually confusing the behavior of SDL_PollEvent with SDL_WaitEvent.