libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
404 stars 37 forks source link

win stop responding when there is no `tcod.event.get()` #114

Closed UcyElak closed 2 years ago

UcyElak commented 2 years ago

Hi, HexDec! I find that the window will stop responding if no tcod.event.get() is called in the main loop, on Win10 and python3.7. I'm new to python-tcod, so I do not actually know what happened in sdl event functions or whether it is expected.

It might be better to add a comment on getting started or add protect on related functions.

HexDecimal commented 2 years ago

This is normal behavior for SDL-based programs. Event polling is how your program tells Windows that your app isn't hanging.

SDL has SDL_PumpEvents which lets you keep the window awake without needing to handle the events immediately. You can call this function from tcod using tcod.lib.SDL_PumpEvents().

HexDecimal commented 2 years ago

There isn't much more to add. A program does need to check events at least to respond to quit events and other windowing events. SDL_PumpEvents causes important side-effects so I won't add it to non-event functions.

A main loop without event polling might be considered invalid. Something like a long loading screen might use SDL_PumpEvents or it might check events normally for its duration. What example do you have for a program which doesn't check events?

UcyElak commented 2 years ago

Hi, HexDec I'm working on the first demo, so there is no event handle function yet. I agree that it at least need to respond for quit, and maybe I have to learn more on SDL to work better with tcod. XD Thanks for your help!

HexDecimal commented 2 years ago

No problem. Keeping the event loop from the getting started examples should be enough. You only need to replace tcod.event.wait with tcod.event.get.