Jump to content

[SOLVED] while () wait 1; weird problem


photo

Recommended Posts

Posted

After finding a weird DialogFile behaviour, I tried a different approach: checked source code and tried to implement my own file selector dialog using WidgetDialogFile:

 

class Window {

WidgetDialogFile df;
WidgetButton ok_b;
WidgetButton cancel_b;
string fileName;

void load_clicked() {

    df = new WidgetDialogFile(gui);
    ok_b = df.getOkButton();
	cancel_b = df.getCancelButton();
	ok_b.setCallback(GUI_CLICKED,"Dilogus::Window::load_button",1);
	cancel_b.setCallback(GUI_CLICKED,"Dilogus::Window::load_button",0);
    df.setFilter("*.xml");  

    df.setMoveable(1);
	df.setSizeable(1);
	df.setTitleable(0);
	df.setBlendable(0);
	df.setFloatable(0);
	df.setSnapDistance(16);
	df.setTextAlign(GUI_ALIGN_LEFT);
	df.arrange();
	gui.addChild(df,GUI_ALIGN_CENTER | GUI_ALIGN_OVERLAP);
    df.setPermanentFocus();

    // wait for result
    dlg_res = -1;
    printf("After dlg_res=-1 \n");
	while(dlg_res < 0) wait 1;

And here is the problem. After while(dlg_res < 0) wait 1; my widgets (all of them) become invalid. In fact, the loop is executed only once and the script continues. Im thinking that maybe the previous problem I reported and this one can be related, and probably the cause is something Im doing wrong, but cant find what is it.

  • 1 year later...
Posted

When I have to wait for a variable to attain a certain value, I use threading. This prevents Unigine from re executing the entire function on the next frame. Instead, threaded functions are executed in after init(), update(), shutdown(). Also, threads have their own scope, therefore, I would include the object as a function parameter and access properties from it. My code would go something like this:

 

class Window {
int dlg_res;
void load_clicked() {
   	//code here
   	//code here
   	thread("WaitForResult", this);
}
void WaitForResult (Window instance) {
   	while (instance.dlg_res < 0) {
       	wait;
   	}
   	//some code here
}
};

Posted

Hi,

 

'wait' statement can be used only in threads.

×
×
  • Create New...