Wxwidgets refresh too slow? (w/segmentation fault)

I’m writing a little program with a GUI interface that launches several sorting algorithms ported in Haxe. I launched the main loop inside a thread and, to avoid double clicks on the “run” button, I disable the button before the loop and re-enable it ounce the loop is over. I also use a label as a kind of status bar to show the current algorithm being processed. Since hxWidgets is compiled in C++, it’s very quick and for a few elements to order the program terminates the work in a short time. This causes the GUI not to be refreshed properly: the label I use to show the current algorithm isn’t set to the default “ready” message, while the button is. While, if I use a lot of items, the GUI seems to have to proper time to process the events and reset the label to “ready”. Occasionally, I also get some segmentation fault errors, and a couple of other errors I got today. The first one:

Debug: window wxButton@0x5d2c08f8c0f0 ("Run") lost focus even though it didn't have it

The second one:

**
Gtk:ERROR:../gtk/gtk/gtkcssnode.c:319:lookup_in_global_parent_cache: assertion failed: (node->cache == NULL)
Bail out! Gtk:ERROR:../gtk/gtk/gtkcssnode.c:319:lookup_in_global_parent_cache: assertion failed: (node->cache == NULL)
zsh: IOT instruction (core dumped)  ./Main

This is the portion of the code that calls the main loop:

private function launchApp() {
        var thread = Thread.create(function() {
            runTest();
        });
    }
    
    private function runTest() {
        btnRun.disabled = true;
        sortTesting();
        btnRun.disabled = false;
        statusBar.text = "Ready";

private function sortTesting() {
        // ....cut here....
        for (i in 0...sortingAlgorithms.length) {
            var algName = sortingAlgorithms[i].get_name();
            statusBar.text = ("Running " + algName + "...");
       // ... cut here.....

The strange thing is that the button is properly re-enabled even though the loop takes a very short time while the label is set to the default value only if the loop is long enough to do the change, otherwise keep the last change made in the loop.
Is there a way to force the GUI to “flush” all the pending changes to the various widgets?

Thank you

I think you should change buttons etc in the main thread. Like basically all UI stuff in the main thread.

This makes sense, other graphical toolkits require that UI changes should be done in the main loop, too. But this contrasts with the use of threads because once they are started, I have no way to wait for their completion, so the launch button is reactivated immediately. It doesn’t seem to me that there is way to launch the threads and wait for them to finish while the main loop continues to manage the refresh of the interface, a sort of the ‘thread.join’ found in Python, to be clear. I will have to look for another way to get this behaviour.
Thank you for your reply

Not sure but you can maybe just do
MainLoop. runInMainThread when you want to change something wx related haxe.MainLoop - Haxe 4.3.6 API but yeah you’ll to explore.

I solved it, but only partially. Since I’m updating a tableview, I hooked a function to the onAdd event of the datasource I’m using, and then I count how many elements have been added: when I reach the desired number, I re-enable the button. The problem that I haven’t solved yet is that sometimes, after several launches of the app, it continues to crash with a segmentation fault. But it could also be due to my ignorance in something, since I’ve been using Haxe and HaxeUI for a few weeks.