Search code examples
androidlibgdx

calling stage.act call in different thread a good idea in libgdx?


Will calling stage.act on a seperate thread within an infinite loop is a good idea? Is there any pros and cons on this approach?

I've tried doing it,but im not sure if this will cause problem in the long run. it looks faster though.


Solution

  • From LibGDX documentation:

    No class in libgdx is thread-safe unless explicitly marked as thread-safe in the class documentation.

    You should never perform multi-threaded operations on anything that is graphics or audio related, e.g. use scene2D components from multiple threads.

    From Stage api:

    The Stage and its constituents (like Actors and Listeners) are not thread-safe and should only be updated and queried from a single thread (presumably the main render thread).

    So how you can see, it's a bad idea.