Jump to content

Can't remove Input::CALLBACK_IMMEDIATE_INPUT callbacks


photo

Recommended Posts

Hi,

We have some Input::CALLBACK_IMMEDIATE_INPUT callbacks.

But the remove/clear callbacks functions don't remove the added callbacks

on_immediate_input_callback = MakeCallback(this, &InteractiveWorldLogic::on_immediate_input);
Input::addCallback(Input::CALLBACK_IMMEDIATE_INPUT, on_immediate_input_callback);
// now try to remove it
Input::removeCallback(Input::CALLBACK_IMMEDIATE_INPUT, on_immediate_input_callback);
// it's still there
Input::clearCallbacks(Input::CALLBACK_IMMEDIATE_INPUT);
// nope, still there also!

This is problematic because at shutdown, the callback is still called when we enter "quit" in the console, and the code crash...

int MyWorldLogic::shutdown()
{
	Input::removeCallback(Input::CALLBACK_IMMEDIATE_INPUT, on_immediate_input_callback);
    // doesn't work, the callback is still called if I type "quit" in the console
}

void MyWorldLogic::on_immediate_input(InputEventPtr e)
{
	if (Console::isActive()) //<--crash, because engine is already destroyed
		return;
    ...
}

Are we mis-using the API?

Link to comment

Hello,

To remove callbacks you need to use the identifier that is returned when adding.

class AppWorldLogic : public Unigine::WorldLogic
{
	//...
private:
	void on_immediate_input(InputEventPtr e);

	void *callback_id{nullptr};
};

int AppWorldLogic::init()
{
	callback_id = Input::addCallback(Input::CALLBACK_IMMEDIATE_INPUT, MakeCallback(this, &AppWorldLogic::on_immediate_input));
	return 1;
}

int AppWorldLogic::shutdown()
{
	Input::removeCallback(Input::CALLBACK_IMMEDIATE_INPUT, callback_id);
	return 1;
}

Also currently the Input::clearCallbacks() method has an empty implementation, because internally the engine now uses the same callbacks. This will be fixed in the future with an updated event system.

Link to comment
×
×
  • Create New...