User avatar
jsantos
Site Admin
Posts: 2947
Joined: 20 Jan 2012, 17:18
Contact:

Re: Cannot unregister routed event handler (v2.0.1f1, C++)

02 Sep 2017, 15:10

Oh! This is great! Thanks for sharing this workaround, it will be helpful for more people.
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: Cannot unregister routed event handler (v2.0.1f1, C++)

05 Sep 2017, 02:26

Unfortunately I found a flaw in the workaround. This is due to the nature of rxcpp.

Difficult to explain unless you are familiar with rxcpp. But let me try ...

There are cases where the line
subscriber.on_next(param);
initiate the observable's unsubscription, which calls the following lines (lambda passed to subscriber.add())
            subscriber.add([_ev, wrapper]() {
                // In the event of unsubscribe, remove the callback from the NoesisGUI event
                auto ev = const_cast<C<Delegate<Ret(Args...)>> &>(_ev);
                ev -= MakeDelegate(wrapper.get(), &FunctorToDelegate<Ret, Args...>::Invoke);
            });
When the lambda returned, rxcpp removed it from its internal structure, resulting the captured 'wrapper' shared pointer is destroyed.

Because of it, when the line subscriber.on_next(param) returned, its lambda container 'wrapper' has already gone, crashing the program.

So, I think I still really need NoesisGUI to allow us to store lambda or std::function for Event delegates...
 
User avatar
jsantos
Site Admin
Posts: 2947
Joined: 20 Jan 2012, 17:18
Contact:

Re: Cannot unregister routed event handler (v2.0.1f1, C++)

06 Sep 2017, 18:09

Thanks for the detailed explanation. And yes, we undoubtedly need to solve the issue with the fixed limit in our delegates.

Who is online

Users browsing this forum: No registered users and 0 guests