Page 1 of 1

Calling a function from CTRL++ in control extension causes crash

Posted: Wed Feb 26, 2020 11:41 am
by ozangor
Hi there,

We have implemented a special communication protocol. In a control manager, we are managing multiple connections by giving some connection ids. Whenever a message is received, a function in c++ is called by the library. That callback function also calls a registered CTRL++ function.

Whenever we receive a lot of messages simultaneously or consecutively and fast enough, mostly the control manager crashes silently, but sometimes it reads "error unwinding stack" etc.

What is the best approach to call functions in of CTRL in control extensions, in order to avoid race conditions. Does the api provide something to help run CtrlFunc's in a synchronous way?

The callback function in the control extension is as follows:

Code: Select all

	converters::frame_to_json_converter<json::json_template_complete> fjc(CtrlCmdInterfaceExternHdl::jtc);

	auto frame_json = fjc.convert_frame_to_json(frame);

	RecVar vars;

	auto var = converters::wstring_to_string(frame_json);
	vars.append(new TextVar(var.c_str()));
	vars.append(new TextVar(host));
	vars.append(new UIntegerVar(port));

	Controller* p = Controller::thisPtr;
	//p->startFunc(callback, &vars);
	try
	{
		CharString con_callback = "returnResponse";
		for (auto const& conn : CtrlCmdInterfaceExternHdl::active_connections)
		{
			if (conn.second.is_equal(host, port))
			{
				con_callback = conn.second.callback_func;
			}
		}
		CtrlThread *thread = 0;
		CtrlFunc *func = Controller::thisPtr->findFunc(con_callback, CtrlCmdInterfaceExternHdl::scr);
		CtrlCmdInterfaceExternHdl::scr->startThread(thread, func, &vars);
	}

Re: Calling a function from CTRL++ in control extension causes crash

Posted: Thu Feb 27, 2020 5:00 pm
by gschijndel
You should pass a 'RecVar*' to the 'startThread' function, because the thread is only started (the function might continue to run after this C++ scope has finished).

Re: Calling a function from CTRL++ in control extension causes crash

Posted: Mon Mar 02, 2020 9:17 am
by ozangor
Thanks for the answer. I was blindly looking at the function call actually :) Thought I was just passing a copy of the object, but it was a ref.