Pushing change event from Windows device compiled with cppTango v9.4.0 crashes

Related to PyTango 9.4 CI testing under Windows, the tests that push change events cause the device server to crash with a nullptr access violation. This is on both AppVeyor and a Windows 10 laptop, so it doesn't appear to be environment specific.

The PyTango test for pushing data-ready events and for interface changed events work fine.

I can cause the same crash with a modified TangoTest device using cppTango directly. (Or maybe I just wrote the wrong C++ code!)

How to cause it

Changes to push event when DevDouble command is executed:

diff --git a/TangoTest.cpp b/TangoTest.cpp
index d55f204..5c7aaed 100644
--- a/TangoTest.cpp
+++ b/TangoTest.cpp
@@ -3376,7 +3376,9 @@ Tango::DevDouble TangoTest::dev_double(Tango::DevDouble argin)
        Tango::DevDouble argout;
        DEBUG_STREAM << "TangoTest::DevDouble()  - " << device_name << std::endl;
        /*----- PROTECTED REGION ID(TangoTest::dev_double) ENABLED START -----*/
-
+    INFO_STREAM << "TangoTest::DevDouble() - pushing double_scalar event... " << device_name << std::endl;
+    push_change_event("double_scalar", &argin);
+    INFO_STREAM << "TangoTest::DevDouble() - pushed double_scalar event. " << device_name << std::endl;
         //     Add your own code
         // Tangotest : just send back input argument
         return argin;
diff --git a/TangoTestClass.cpp b/TangoTestClass.cpp
index 94ac41c..cd3138d 100644
--- a/TangoTestClass.cpp
+++ b/TangoTestClass.cpp
@@ -936,6 +936,8 @@ void TangoTestClass::attribute_factory(std::vector<Tango::Attr *> &att_list)
        //      min_warning     not set for double_scalar
        //      delta_t not set for double_scalar
        //      delta_val       not set for double_scalar
+
+       double_scalar->set_change_event(true, false);

        double_scalar->set_default_properties(double_scalar_prop);
        //      Not Polled

Run the device, and subscribe via PyTango DeviceProxy. Executing the command causes a crash if there is a subscriber.

>>> import tango
>>> dp = tango.DeviceProxy("tango://localhost:8888/a/b/c#dbase=no")
# using the command without a subscriber works fine
>>> dp.DevDouble(1.5)
1.5

# now subscribe
>>> cb = tango.utils.EventCallback()
>>> eid = dp.subscribe_event("double_scalar", tango.EventType.CHANGE_EVENT, cb)
2022-11-10 14:08:15.496280 A/B/C DOUBLE_SCALAR#DBASE=NO CHANGE [ATTR_VALID] 201.73105033133845

# executing command causes a server crash
>>> dp.DevDouble(1.5)
Traceback (most recent call last):
...
PyTango.ConnectionFailed: DevFailed[
DevError[
    desc = TRANSIENT CORBA system exception: TRANSIENT_CallTimedout
  origin = void __cdecl Tango::Connection::connect(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) at (C:\projects\cppTango\cppapi\client\devapi_base.cpp:604)
  reason = API_CorbaException
severity = ERR]

DevError[
    desc = Failed to connect to device a/b/c
  origin = void __cdecl Tango::Connection::connect(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &) at (C:\projects\cppTango\cppapi\client\devapi_base.cpp:604)
  reason = API_ServerNotRunning
severity = ERR]
]

I made a debug build and there are some clues. It seems strange that the stack points to a DevVarBooleanArray when we are working with a DevDouble.

Debug build and debugger screenshots

Compilation on Windows machine, in x64 Native Tools Prompt for VS 2022:

git clone https://gitlab.com/tango-controls/TangoTest.git
cd TangoTest
git checkout 3.6

# edit files as per diff.

set ARCH=x64
set CMAKE_GENERATOR=Visual Studio 17 2022
set TANGO_ROOT=C:/projects/libtango/libtango_9.4.0_v141_x64_static_debug

mkdir build
cd build
cmake -G "%CMAKE_GENERATOR%" -A %ARCH%  .. -DTANGO_PKG_LIBRARY_DIRS="%TANGO_ROOT%\lib" -DTANGO_PKG_INCLUDE_DIRS="%TANGO_ROOT%\include" -DTANGO_PKG_LIBRARIES="comctl32;libtangod;omniORB4d;omniDynamic4d;COS4d;omnithreadd;libzmq-v141-mt-sgd-4_0_5" -DTANGO_PKG_CFLAGS_OTHER="/MTd" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDebug" --install-prefix c:\projects\TangoTest\bin
cmake --build . --config Debug

image

image

This was using the 9.4.0.windows0 release, libtango_9.4.0_v141_x64_static_debug.zip and libtango_9.4.0_v141_x64_static_release.zip.