Page 2 of 2

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

Posted: 02 Sep 2017, 15:10
by jsantos
Oh! This is great! Thanks for sharing this workaround, it will be helpful for more people.

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

Posted: 05 Sep 2017, 02:26
by nikobarli
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...

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

Posted: 06 Sep 2017, 18:09
by jsantos
Thanks for the detailed explanation. And yes, we undoubtedly need to solve the issue with the fixed limit in our delegates.