blocking function no gui refresh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gejza

Hi,

i have a long running function (about 3-5 sec) which blocks the GUI.
It blocks the editor profiler too.
I tried with difference method to refresh the GUI, without a good result.

For example:
get_node(“WAITING LABEL”).show()
runLongFunction()
get_node(“WAITING LABEL”).hide()

I tried it with thread, the result is the same. No waiting label, no anim, etc. :confused:

Is there any solution for a long running function to easy visualize?

Thanx

Long tasks should be run in a seperate thread. If a thread is blocking your GUI maybe you’re not using it correctly? Check this official example:
https://github.com/godotengine/godot-demo-projects/tree/3.0-d69cc10/misc/threads

hilfazer | 2018-09-22 08:29

:bust_in_silhouette: Reply From: Andrea

can you provide a rough structure of how your thread starts and ends?
I also had some problems with threads, maybe this link might help you:
https://forum.godotengine.org/33120/how-do-thread-and-wait_to_finish-work

Finally i solve it.

My problem was: in main thread and in the long running function thread both i should update the GUI, but it works now.

Solution:
i have a semaphore, which i set, to signal the thread to enable running. (it’s agains polling)
Then in the thread where i do the “heavy lifting”, after GUI update, need a minimal wait, to give the main thread a little time to refresh the GUI.
If thread is ready, then sink semaphore, to be ready to run again.

gejza | 2018-09-26 03:00