Segmentation fault when subscribing to events

Hi,

i wrote a Device Server that subscribe to events with many device attributes and different data types… I implements only one callback method which is triggered when the events are received (push model).
I have an segmentation fault when receiving an event with data type different from the subscription one…
The problem comes from the allocation of the array in the cb.

i simply tried with tangotest and i have the same error ;(

extract of example subscribe event (data type of the attribute is DevDouble):


		      try
			{
			  the_device = new Tango::DeviceProxy("sys/tg_test/1");
			  if (the_device->state() == Tango::FAULT)
			    {
			      set_state(Tango::FAULT);
			    }
			  else
			    {
			    
			      cb = new DoubleEventCallBack();
			      if (cb!=NULL)
				event_id=the_device->subscribe_event("long_scalar_w",Tango::CHANGE_EVENT,cb);
			    }
			}
		      catch(Tango::DevFailed &e)
			{
			  set_state(Tango::FAULT);
			}



extract of the callback (array declaration in DevLong):


  void DoubleEventCallBack::push_event(Tango::EventData *myevent)
  {

    Tango::DevVarLongArray *double_value;

    try
      {
	  if(!myevent->err)
	    {
	      *(myevent->attr_value) >> double_value;
	      delete double_value;
	    }
      }
    catch(int e)
      {
	cout << "DoubleEventCallBack::push_event(): could not extract data!\n";
      }
  }

Is it the good way to do this when i have to subsribe to events on dynamic attributes unknown in advance ?
Thanks for help

Hi,

In your callback,

myevent->attr_value->data_type

gives you the type of the received event data (int corresponding to the index of the type in enum CmdArgType type declared in tango_const.h include file).

You can then adapt your code depending on the received type.

By the way, you should catch Tango::DevFailed exceptions (not int exceptions) in your callback when you try to extract the data.

Did you prefix it with the namespace Tango?
e.g.: Tango::DEV_SHORT ?

The data type is transmitted on the network only since Tango 9 (IDL 5).
Are you subscribing to Tango 8 devices?
Maybe what you are observing is a consequence of the fix of DevShort attribute change event has wrong data_type · Issue #248 · tango-controls/cppTango · GitHub ?

Late answer :frowning:

Not effectively. I’m going to try.

All Tango 9 devices.

Thanks again.