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

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
3 posts • Page 1 of 1
ozangor
Posts: 44
Joined: Thu Sep 22, 2011 2:57 pm

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

Post 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);
	}

gschijndel
Posts: 373
Joined: Tue Jan 15, 2019 3:12 pm

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

Post 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).

ozangor
Posts: 44
Joined: Thu Sep 22, 2011 2:57 pm

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

Post 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.

Post Reply
3 posts • Page 1 of 1