Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Thread Safety]'set_text()' on a LUILabel causes AssertionError if called from secondary Thread #50

Open
Nel-Fie opened this issue Aug 30, 2018 · 0 comments

Comments

@Nel-Fie
Copy link

Nel-Fie commented Aug 30, 2018

I've implemented a thread from direct.stdpy.threading in a project, and the function set_text() is sometimes called from that thread (i.e. not 'Main Thread'). Most of the time this simply causes the text not to update properly or to be incomplete/glitched when rendered, but it occasionally causes an AssertionError that crashes the P3D app, with the following error message:

File "C:\Program Files\Python36\lib\site-packages\lui_builtin\LUILabel.py", line 62, in set_text
    self._text.text = str(text)
AssertionError: _sprite_index >= 0 at line 264 of A:\Programming\LUI-master\source\luiSprite.cxx
 
Process finished with exit code 255

The exit code is not always the same. The error is caused by the Main Thread rendering a frame while the secondary thread is still operating on the LUI Label.

Until a LUI-internal solution is worked out, here's a workaround that might help those facing this problem:

  1. Get a render lock via base.graphicsEngine.getRenderLock() and store it at hand of whatever code that will call on your LUI object(s) from another thread. (e.g. store it as self.lock = base.graphicsEngine.getRenderLock())
  2. Before your call to a function from your LUI object(s), get your render lock. (e.g. lock = self.lock)
  3. Call lock.acquire().
  4. Perform whatever call or other operations you need on your LUI object(s).
  5. Call lock.release().

This ensures that the Main Thread will wait for the call to finish before rendering the frame.

Credits: All information about this error as well as the workaround were provided by rdb over the P3D IRC channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant