Threads, images, and window updating

I’m writing an application where the code is responsible for creating the UI display on the fly. I do this by creating an image and attaching it to a button that’s the size of the window. That’s working just fine. My issue is that I have a separate thread from the thread that’s executing PtMainLoop that receives data and then triggers an update of the button widget. I’m using PtDamageExtent on the button widget and am getting a segmentation fault.

I know that the basic image rendering works correctly because I can cover and uncover the window and my image is drawn correctly. It’s only when I try and call PtDamageExtent to trigger the update from the other thread that I hit the fault. Since the documentation says No under safety for PtDamageExtend, I’m guessing that it’s not safe to call from other threads than the one running PtMainLoop.

Looking through the docs, it appears that most of the Ptxxx calls aren’t safe to invoke from other threads. So my question is what’s the proper way to trigger a display update from a separate thread? I’m guessing that I need to send a message to the PtMainLoop but haven’t figured out what/how yet.

Any help would be greatly appreciated.

Photon is indeed not thread safe. Register an event handler on the main thread and trigger that event from the other thread. Look it up in the documentation.

I found that bracketing the call to PtDamageExtent and PtEnter(0) and PtLeave(0) seems to fix my crash problem.

That solution has draw back. Usually when one does a thread in photon it’s to let it handle a somewhat real-time operation, but using PtEnter, actually binds you thread with the main process. If the main process is doing a lengthy operation inside a callback, then PtEnter can be blocked for a long time, as long as the callbacks are running.

This may or may not be an issue in your design.