Jump to content

Error while setting callback for Widget


photo

Recommended Posts

I have the below script in my world.cpp

// Unigine script
namespace Widgets
{
WidgetButton CreateButton()
{
	Gui gui = engine.getGui();
	WidgetButton widgetButton = new WidgetButton(gui);
	gui.addChild(widgetButton, GUI_ALIGN_EXPAND);
	widgetButton.setCallback(GUI_CLICKED, "Widgets::Button_Clicked");
	return widgetButton;
}

void Button_Clicked()
{
	// Do stuff....
}
}

 

I call this CreateButton funtion from C++:

engine->runWorld("Widgets::CreateButton");

Unigine crashes at the line:

widgetButton.setCallback(GUI_CLICKED, "Widgets::Button_Clicked");

unigineerror.jpg

 

I tried push/popWorld, but didn't help.

Link to comment

I have the below script in my world.cpp

// Unigine script
namespace Widgets
{
WidgetButton CreateButton()
{
	Gui gui = engine.getGui();
	WidgetButton widgetButton = new WidgetButton(gui);
	gui.addChild(widgetButton, GUI_ALIGN_EXPAND);
	widgetButton.setCallback(GUI_CLICKED, "Widgets::Button_Clicked");
	return widgetButton;
}

void Button_Clicked()
{
	// Do stuff....
}
}

 

I call this CreateButton funtion from C++:

engine->runWorld("Widgets::CreateButton");

Unigine crashes at the line:

widgetButton.setCallback(GUI_CLICKED, "Widgets::Button_Clicked");

unigineerror.jpg

 

I tried push/popWorld, but didn't help.

 

Please, attach your log.html file located at the bin directory of project and your script so that we could reproduce and fix this.

Link to comment

As a temporal workaround try commenting this line

return widgetButton;

If You will still experience crash, please, post here or send for support@unigine.com a minimal version of your C++ Application so that we could reproduce this issue and find a solution.

Link to comment

I tried your workaround, but still the program is crashing. I have mailed a sample project to support@unigine.com for reproducing the issue.

Link to comment

I tried your workaround, but still the program is crashing. I have mailed a sample project to support@unigine.com for reproducing the issue.

Thank You, we'll try to reproduce this issue now. I will contact you soon.

Link to comment

We found the source of this issue. It is this line that makes unigine crash:

widgetButton.setCallback(GUI_CLICKED, "Widgets::Button_Clicked");

Thank You for pointing this bug for us. We will fix it in the next SDK release approximately in a month.

Link to comment

Thanks mrred.

 

For the time being, is there any work around for this? In our project, we need to set the callback from C++ side.

Link to comment

You can use deferred execution to make a callback for widget.

 

Example:

 

[C++: main.cpp]

#include <Unigine.h>
#include <UnigineInterpreter.h>

using namespace Unigine;

int main(int argc, char * argv[]) {

Engine * engine = Engine::init(UNIGINE_VERSION, argc, argv);

int count = 5; // For delay
Variable command("CreateButton");

while (!engine->isDone()) {
	if(count == 0) {
		engine->runWorld("addDeferredExecution",command);
		count = -1;
	} else if(count > 0) {
		count--;
		Log::warning("count = %d \n",count);
	}

	engine->update();
	engine->render();
	engine->swap();
}

engine->shutdown();

return 0;
}

 

 

[unigineScript: world1.cpp]

/*
*/
string deferred_executions[0];

/*
*/
int init() {
engine.game.setPlayer(new PlayerSpectator());
return 1;
}

/*
*/
int shutdown() {
return 1;
}

/*
*/
int update() {
if(deferred_executions.size() > 0) {
	forloop(int i = 0; deferred_executions.size()) {
		string command = deferred_executions[i];
		log.message("call command '%s'\n",command);
		engine.world.call(deferred_executions[i]);
	}
	deferred_executions.clear();
}
return 1;
}

/* 
*/
void addDeferredExecution(string command) {
log.message("add command '%s'\n",command);
deferred_executions.append(command);
}

/* 
*/
void CreateButton() {
Gui gui = engine.getGui();
WidgetButton widgetButton = new WidgetButton(gui);	
widgetButton.setCallback(GUI_CLICKED,"call_back");
gui.addChild(widgetButton, GUI_ALIGN_LEFT);
log.message("CreateButton \n");
}

/*
*/
void call_back() {
engine.console.print("In call_back()\n");
}

Link to comment
×
×
  • Create New...