Closing Dialog from a C++ plugin without success.

Typically: "How do I... ", "How can I... " questions
Post Reply
SkySurfer1
Posts: 10
Joined: 14 Mar 2016, 14:34

Closing Dialog from a C++ plugin without success.

Post by SkySurfer1 » 11 May 2016, 14:38

Hi,

I created an image filter plug-in which connects on simStart to an external application using network sockets. To give a feedback by stimulation could be freeze for a moment until connection is established and image resolution informations are exchanged I wanted to show an dialog.
So I placed the following line into my code that handel the simStart:

Code: Select all

m_dialogHdl = simDisplayDialog("Waiting...", "Waiting for connection ...", sim_dlgstyle_message, NULL,NULL, NULL, NULL);
As information on image resolution etc. is first available after the reception of the first image in imageFilterProcess message I stored the handle in a member variable and try to close it after connection is established and configured with:

Code: Select all

if (m_dialogHdl != -1)
{
     simInt result = simEndDialog(m_dialogHdl);
     std::cout << "Result : " << result << std::endl;
}
But here I always get the result : -1 and dialog can't be closed during the simulation.

How can I close this dialog?

coppelia
Site Admin
Posts: 7388
Joined: 14 Dec 2012, 00:25

Re: Closing Dialog from a C++ plugin without success.

Post by coppelia » 11 May 2016, 17:53

Hello,

can you check what simGetLastError returns just after trying to end the dialog?

Cheers

SkySurfer1
Posts: 10
Joined: 14 Mar 2016, 14:34

Re: Closing Dialog from a C++ plugin without success.

Post by SkySurfer1 » 12 May 2016, 10:41

Hi,

simGetLastError() returns an empty string :(

coppelia
Site Admin
Posts: 7388
Joined: 14 Dec 2012, 00:25

Re: Closing Dialog from a C++ plugin without success.

Post by coppelia » 13 May 2016, 13:39

can you try with following message routine? This shopuld display a dialog at start-up, and as soon as you start simulation, the dialog should disappear:

Code: Select all

VREP_DLLEXPORT void* v_repMessage(int message,int* auxiliaryData,void* customData,int* replyData)
{
	int errorModeSaved;
	simGetIntegerParameter(sim_intparam_error_report_mode,&errorModeSaved);
	simSetIntegerParameter(sim_intparam_error_report_mode,sim_api_errormessage_ignore);
	void* retVal=NULL;
	static bool simulating=false;
	static int m_dialogHdl=-1;


	if (message==sim_message_eventcallback_instancepass)
	{
		static int cnt=0;
		if (cnt==0)
		{
			m_dialogHdl = simDisplayDialog("Waiting...", "Waiting for connection ...", sim_dlgstyle_message, NULL,NULL, NULL, NULL);
			printf("opened dlg with handle: %i\n",m_dialogHdl);
		}
		cnt++;
	}
	if (message==sim_message_eventcallback_simulationabouttostart)
		simulating=true;
	if (message==sim_message_eventcallback_simulationended)
		simulating=false;
	if (simulating)
	{
		if (m_dialogHdl>=0)
		{
			simInt result = simEndDialog(m_dialogHdl);
			printf("Closing dlg: %i\n",result);
			m_dialogHdl=-1;
		}
	}
	simSetIntegerParameter(sim_intparam_error_report_mode,errorModeSaved);
	return(retVal);
}
If it possible that you open the dialog more than once, and that several dialogs are stacked on top of each other? Try to shift the dialog to see if other dialogs are hidden under.

Cheers

coppelia
Site Admin
Posts: 7388
Joined: 14 Dec 2012, 00:25

Re: Closing Dialog from a C++ plugin without success.

Post by coppelia » 13 May 2016, 13:42

Also, you probably can't get the last error because, as in the previous routine, we set errors to be ignored. Try commenting the 3 first lines of the v_repMessage function.

Cheers

SkySurfer1
Posts: 10
Joined: 14 Mar 2016, 14:34

Re: Closing Dialog from a C++ plugin without success.

Post by SkySurfer1 » 17 May 2016, 10:24

When I replace my v_repMessage funtion with yours the dialog box disappears.

I commented out the error suppression in my code and got the following error:

Result -1
Error: Could not lock resources for data write operation. (simEndDialog)

What condition can cause this? Threading issue? because I only try to close the dialog within the filterprocess and your approach try it every message until it's closed

coppelia
Site Admin
Posts: 7388
Joined: 14 Dec 2012, 00:25

Re: Closing Dialog from a C++ plugin without success.

Post by coppelia » 17 May 2016, 17:14

Ok, then it seems that you are trying to access the V-REP API from the GUI thread (or another thread that V-REP didn't launch). This is forbidden, except in special cases.
What you should do is (for instance) set a flag when you want to display that dialog (if you currently are in the GUI thread), and once your message function is called, you should react to that flag and execute the desired function call. There are more elegant ways to do this with Qt's signal/slot mechanism, but that's the basic idea.

Cheers

Post Reply