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

JuliaDisplay flickers when updated too frequently #143

Open
f-ij opened this issue May 4, 2022 · 3 comments
Open

JuliaDisplay flickers when updated too frequently #143

f-ij opened this issue May 4, 2022 · 3 comments
Assignees
Milestone

Comments

@f-ij
Copy link

f-ij commented May 4, 2022

I'm building an interface for a simulation. I'm using the ising display type to push a matrix of pixels to the QML interface. I'm doing this asynchronously, so I'm calling a function using Threads.@Spawn on a while loop that displays the matrix. If I do this more often than about 30 times a second, the display will flicker, disappearing for a short while intermittently.

@barche
Copy link
Collaborator

barche commented May 15, 2022

I have tried to create a minimal example in threadedcanvas.jl and threadeddisplay.jl in the qt6 branch here: https://github.com/barche/QmlJuliaExamples/tree/qt6

Unfortunately, I couldn't really get it to work. The idea is that pushing to a display (or anything in QML) directly from a separate thread is not supported. In these examples, I try to keep the display on the main GUI thread, but for some reason both the "simulation" thread (which continuously grows and shrinks a circle) needs to yield after each update, even though I am running this with -t2 and I see 2 CPUs working. On Linux, the display example doesn't work at all, the canvas example (faster theoretically) works only with yield. Without yielding, I get the frezzing problem you mentioned in issue #142.

I'm afraid I don't understand Julia threads well enough to make any more progress on this.

@barche
Copy link
Collaborator

barche commented May 17, 2022

This is now fixed in commit barche/QmlJuliaExamples@1056ec8

The main problem (at least in my example) was that I wasn't allocating anything in the "simulation" thread, and in that situation a call to GC.safepoint() must be inserted.

So the proper way to do this is to use the QML Timer, as done in threadedcanvas.jl and threadeddisplay.jl. Note that if you are displaying an image, the canvas approach is much faster. By calling a display or canvas render function from a QML Timer, you are making sure the update happens from the main thread. You can then experiment with the rate on the timer, slower machines may need longer intervals, the display example runs too slowly on my Mac and that makes the update stutter (display function takes longer than the timer interval).

@ufechner7
Copy link
Member

Suggestion: Add an FAQ section to the documentation and explain the solution.

@ufechner7 ufechner7 self-assigned this Oct 23, 2023
@ufechner7 ufechner7 added this to the 0.8.2 milestone Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants