View Issue Details

IDProjectCategoryView StatusLast Update
0003350NoesisGUIC++ SDKpublic2024-06-05 18:05
Reporternikobarli Assigned Tojsantos  
PrioritynormalSeverityblock 
Status resolvedResolutionfixed 
Product Version3.2.3 
Target Version3.2.4Fixed in Version3.2.4 
Summary0003350: Crash when calling Keyboard::Focus() inside DataContextChanged handler
Description

We are now upgrading Noesis to version 3.2.3 and we found some scenarios that caused crashes.
We tracked down the reason of this behavior, due to calling Keyboard::Focus() inside DataContextChanged handler.
It seems that Keyboard::Focus() clears the previously set DataContextChanged handlers and causes exception when the code tries to execute the handlers.

Please find a simple patch to reproduce this issue using your Buttons sample project.

The same patch doesn't cause crash when applied to version 3.1.3 we used before, and the two DataContextChanged handlers are correctly called.

Steps To Reproduce

Please apply the patch and run Sample Button project.

Attached Files
crash.patch (2,376 bytes)   
Index: Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.cpp
===================================================================
--- Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.cpp	(revision 172871)
+++ Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.cpp	(working copy)
@@ -8,6 +8,7 @@
 #include "ViewModel.h"
 
 #include <NsGui/IntegrationAPI.h>
+#include <NsGui/Keyboard.h>
 #include <NsGui/Uri.h>
 #include <NsCore/ReflectionImplementEmpty.h>
 
@@ -20,6 +21,8 @@
 MainWindow::MainWindow()
 {
     Initialized() += MakeDelegate(this, &MainWindow::OnInitialized);
+    DataContextChanged() += MakeDelegate(this, &MainWindow::DelegateFunc1);
+    DataContextChanged() += MakeDelegate(this, &MainWindow::DelegateFunc2);
     InitializeComponent();
 }
 
@@ -36,6 +39,19 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
+void MainWindow::DelegateFunc1(BaseComponent*, const DependencyPropertyChangedEventArgs&)
+{   
+    // As a result of calling the following method, DelegateImpl<Ret (Args...)>::MultiDelegate::~MultiDelegate() is called
+    GetKeyboard()->Focus(this);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void MainWindow::DelegateFunc2(BaseComponent*, const DependencyPropertyChangedEventArgs&)
+{
+    // DelegateImpl<Ret (Args...)>::MultiDelegate::mInvoker is destroyed before this delegate is called
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
 NS_BEGIN_COLD_REGION
 
 NS_IMPLEMENT_REFLECTION_(Buttons::MainWindow, "Buttons.MainWindow")
Index: Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.h
===================================================================
--- Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.h	(revision 172871)
+++ Native/Src/Packages/Samples/Buttons/Src/MainWindow.xaml.h	(working copy)
@@ -26,6 +26,9 @@
     void InitializeComponent();
     void OnInitialized(BaseComponent*, const Noesis::EventArgs&);
 
+    void DelegateFunc1(BaseComponent*, const Noesis::DependencyPropertyChangedEventArgs&);
+    void DelegateFunc2(BaseComponent*, const Noesis::DependencyPropertyChangedEventArgs&);
+
 private:
     NS_DECLARE_REFLECTION(MainWindow, Window)
 };
crash.patch (2,376 bytes)   
PlatformWindows

Activities

jsantos

jsantos

2024-06-05 18:05

manager   ~0009661

The following patch should fix this issue


Index: Delegate.inl

--- Delegate.inl (revision 14042)
+++ Delegate.inl (working copy)
@@ -277,11 +277,11 @@
{
for (uint32_t i = 0; i < numDelegates - 1; ++i)
{

  • mInvoker->Invoke(i, ForwardArg<Args>(args)...);
  • guard._invoker->Invoke(i, ForwardArg<Args>(args)...);
    }

             // last delegate is used to return a value
  • return mInvoker->Invoke(numDelegates - 1, ForwardArg<Args>(args)...);
  • return guard._invoker->Invoke(numDelegates - 1, ForwardArg<Args>(args)...);
    }
    }

    Please, reopen if necessary.

Issue History

Date Modified Username Field Change
2024-05-29 06:20 nikobarli New Issue
2024-05-29 06:20 nikobarli File Added: crash.patch
2024-05-29 15:12 jsantos Assigned To => sfernandez
2024-05-29 15:12 jsantos Status new => assigned
2024-05-29 15:13 jsantos Target Version => 3.2.4
2024-06-04 13:25 sfernandez Assigned To sfernandez => jsantos
2024-06-05 18:05 jsantos Note Added: 0009661
2024-06-05 18:05 jsantos Status assigned => resolved
2024-06-05 18:05 jsantos Resolution open => fixed
2024-06-05 18:05 jsantos Fixed in Version => 3.2.4