Changing it to a weak pointer indeed helped.
Attached is a patch if you're interested :)

Rostislav.

On 25/08/2015 16:37, Rostislav Khlebnikov wrote:
Hi guys,

I experience a crash upon simply opening and closing my application.
The crash occurs in berryWorkbenchSourceProvider.cpp at line 596.
Seems like the actual window has been already destroyed and focus
changes to the log window, thus the crash.
I think that similarly to the lastActiveWorkbenchWindow, lastActiveShell
and lastActiveWorkbenchWindowShell should be also WeakPointers.

What do you think?

Rostislav.


------------------------------------------------------------------------------
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

>From 841b7d884a0156bc658e37792c6e73472f815472 Mon Sep 17 00:00:00 2001
From: Rostislav Khlebnikov <[email protected]>
Date: Tue, 25 Aug 2015 16:45:51 +0100
Subject: [PATCH] Fixed a crash on exit

---
 .../src/internal/berryWorkbenchSourceProvider.cpp  | 22 ++++++++++------------
 .../src/internal/berryWorkbenchSourceProvider.h    |  4 ++--
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git 
a/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.cpp 
b/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.cpp
index bc61d1b..652697e 100644
--- a/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.cpp
+++ b/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.cpp
@@ -66,8 +66,6 @@ WorkbenchSourceProvider::WorkbenchSourceProvider()
   , lastShowInInput(nullptr)
   , lastEditorInput(nullptr)
   , display(nullptr)
-  , lastActiveShell(nullptr)
-  , lastActiveWorkbenchWindowShell(nullptr)
 {
 }
 
@@ -94,8 +92,8 @@ WorkbenchSourceProvider::~WorkbenchSourceProvider()
   qApp->removeEventFilter(this);
   
HookListener(const_cast<WorkbenchWindow*>(lastActiveWorkbenchWindow.Lock().GetPointer()),
 nullptr);
   lastActiveWorkbenchWindow.Reset();
-  lastActiveWorkbenchWindowShell = nullptr;
-  lastActiveShell = nullptr;
+  lastActiveWorkbenchWindowShell.Reset();
+  lastActiveShell.Reset();
   lastWindow.Reset();
 }
 
@@ -224,9 +222,9 @@ void WorkbenchSourceProvider::WindowOpened(const 
SmartPointer<IWorkbenchWindow>&
 
 void WorkbenchSourceProvider::HandleCheck(const SmartPointer<const Shell>& s)
 {
-  if (s != lastActiveShell)
+  if (s != lastActiveShell.Lock())
   {
-    lastActiveShell = s.GetPointer();
+    lastActiveShell = s;
     CheckActivePart();
     IWorkbenchWindow* window = nullptr;
     if (s.IsNotNull())
@@ -593,9 +591,9 @@ void WorkbenchSourceProvider::HandleShellEvent()
 //  }
 
   LogDebuggingInfo("\tWSP:lastActiveShell: " +
-                   (lastActiveShell ? 
lastActiveShell->GetControl()->objectName() : QString("NULL")));
+                   (!lastActiveShell.Expired() ? 
lastActiveShell.Lock()->GetControl()->objectName() : QString("NULL")));
   LogDebuggingInfo("\tWSP:lastActiveWorkbenchWindowShell: " +
-                   (lastActiveWorkbenchWindowShell ? 
lastActiveWorkbenchWindowShell->GetControl()->objectName() : QString("NULL")));
+                   (!lastActiveWorkbenchWindowShell.Expired() ? 
lastActiveWorkbenchWindowShell.Lock()->GetControl()->objectName() : 
QString("NULL")));
 
   const ISourceProvider::StateMapType currentState = GetCurrentState();
   const Shell::ConstPointer newActiveShell = 
currentState.value(ISources::ACTIVE_SHELL_NAME()).Cast<const Shell>();
@@ -632,8 +630,8 @@ void WorkbenchSourceProvider::HandleShellEvent()
   }
 
   // Figure out which variables have changed.
-  const bool shellChanged = newActiveShell != lastActiveShell;
-  const bool windowChanged = newActiveWorkbenchWindowShell != 
lastActiveWorkbenchWindowShell;
+  const bool shellChanged = newActiveShell != lastActiveShell.Lock();
+  const bool windowChanged = newActiveWorkbenchWindowShell != 
lastActiveWorkbenchWindowShell.Lock();
   const bool toolbarChanged = newToolbarVisibility != lastToolbarVisibility;
   const bool statusLineChanged = newStatusLineVis != lastStatusLineVisibility;
 
@@ -748,8 +746,8 @@ void WorkbenchSourceProvider::HandleShellEvent()
   }
 
   // Update the member variables.
-  lastActiveShell = newActiveShell.GetPointer();
-  lastActiveWorkbenchWindowShell = newActiveWorkbenchWindowShell.GetPointer();
+  lastActiveShell = newActiveShell;
+  lastActiveWorkbenchWindowShell = newActiveWorkbenchWindowShell;
   lastActiveWorkbenchWindow = newActiveWorkbenchWindow;
   lastToolbarVisibility = newToolbarVisibility;
   lastStatusLineVisibility = newStatusLineVis;
diff --git 
a/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.h 
b/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.h
index 16f87cc..a502935 100644
--- a/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.h
+++ b/Plugins/org.blueberry.ui.qt/src/internal/berryWorkbenchSourceProvider.h
@@ -157,7 +157,7 @@ private:
    * <code>null</code> if the last call to
    * <code>Display.getActiveShell()</code> returned <code>null</code>.
    */
-  const Shell* lastActiveShell;
+  WeakPointer<const Shell> lastActiveShell;
 
   /**
    * The last workbench window shell seen as active by this provider. This
@@ -165,7 +165,7 @@ private:
    * <code>workbench.getActiveWorkbenchWindow()</code> returned
    * <code>null</code>.
    */
-  const Shell* lastActiveWorkbenchWindowShell;
+  WeakPointer<const Shell> lastActiveWorkbenchWindowShell;
 
   /**
    * The last workbench window seen as active by this provider. This value may
-- 
1.8.4.msysgit.0

------------------------------------------------------------------------------
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to