Blob Blame History Raw
From 152b0dd43165106f9c01bab33017e23dadf91fb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
Date: Thu, 12 Dec 2013 10:39:06 +0000
Subject: [PATCH 6/9] fix occasional crash on dragging and dropping pages in
 slidesorters

pages go into the cache, and sometimes they get deleted before the
cache gets processed. Remove deleted pages when they go away

Change-Id: I291072a8541f4ca36979e9914975d81cc23a9497
(cherry picked from commit abe9d1463282690313aaf91d2a54011d10b900b9)
(cherry picked from commit 026e9335d792c6557255f064960e0ef6d28728e0)
Reviewed-on: https://gerrit.libreoffice.org/7053
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
---
 sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx | 33 +++++++++++++++++++---
 sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx | 12 ++++++--
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx b/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
index 835787b..cdc2b57 100644
--- a/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
+++ b/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
@@ -94,6 +94,7 @@ RequestQueue::RequestQueue (const SharedCacheContext& rpCacheContext)
 
 RequestQueue::~RequestQueue (void)
 {
+    Clear();
 }
 
 
@@ -120,7 +121,15 @@ void RequestQueue::AddRequest (
     // order.
     sal_Int32 nPriority (mpCacheContext->GetPriority(aKey));
     Request aRequest (aKey, nPriority, eRequestClass);
-    mpRequestQueue->insert(aRequest);
+
+    std::pair<Container::iterator,bool> ret = mpRequestQueue->insert(aRequest);
+    bool bInserted = ret.second == true;
+
+    if (bInserted)
+    {
+        SdrPage *pPage = const_cast<SdrPage*>(aRequest.maKey);
+        pPage->AddPageUser(*this);
+    }
 
     SSCD_SET_REQUEST_CLASS(aKey,eRequestClass);
 
@@ -131,8 +140,11 @@ void RequestQueue::AddRequest (
 #endif
 }
 
-
-
+void RequestQueue::PageInDestruction(const SdrPage& rPage)
+{
+    //remove any requests pending for this page which is going away now
+    RemoveRequest(&rPage);
+}
 
 bool RequestQueue::RemoveRequest (
     CacheKey aKey)
@@ -152,7 +164,11 @@ bool RequestQueue::RemoveRequest (
                 mnMinimumPriority++;
             else if (aRequestIterator->mnPriorityInClass == mnMaximumPriority-1)
                 mnMaximumPriority--;
+
+            SdrPage *pPage = const_cast<SdrPage*>(aRequestIterator->maKey);
+            pPage->RemovePageUser(*this);
             mpRequestQueue->erase(aRequestIterator);
+
             bRequestWasRemoved = true;
 
             if (bRequestWasRemoved)
@@ -229,7 +245,10 @@ void RequestQueue::PopFront (void)
     {
         SSCD_SET_STATUS(maRequestQueue.begin()->mpData->GetPage(),NONE);
 
-        mpRequestQueue->erase(mpRequestQueue->begin());
+        Container::const_iterator aIter(mpRequestQueue->begin());
+        SdrPage *pPage = const_cast<SdrPage*>(aIter->maKey);
+        pPage->RemovePageUser(*this);
+        mpRequestQueue->erase(aIter);
 
         // Reset the priority counter if possible.
         if (mpRequestQueue->empty())
@@ -256,6 +275,12 @@ void RequestQueue::Clear (void)
 {
     ::osl::MutexGuard aGuard (maMutex);
 
+    for (Container::iterator aI = mpRequestQueue->begin(), aEnd = mpRequestQueue->end(); aI != aEnd; ++aI)
+    {
+        SdrPage *pPage = const_cast<SdrPage*>(aI->maKey);
+        pPage->RemovePageUser(*this);
+    }
+
     mpRequestQueue->clear();
     mnMinimumPriority = 0;
     mnMaximumPriority = 1;
diff --git a/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx b/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
index 78a4627..088a135 100644
--- a/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
+++ b/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
@@ -24,7 +24,8 @@
 #include "cache/SlsCacheContext.hxx"
 #include "taskpane/SlideSorterCacheDisplay.hxx"
 #include <drawdoc.hxx>
-#include "osl/mutex.hxx"
+#include <osl/mutex.hxx>
+#include <svx/sdrpageuser.hxx>
 
 
 namespace sd { namespace slidesorter { namespace cache {
@@ -34,11 +35,11 @@ class RequestData;
 /** The request queue stores requests that are described by the RequestData
     sorted according to priority class and then priority.
 */
-class RequestQueue
+class RequestQueue : public sdr::PageUser
 {
 public:
     RequestQueue (const SharedCacheContext& rpCacheContext);
-    ~RequestQueue (void);
+    virtual ~RequestQueue();
 
     /** Insert a request with highest or lowest priority in its priority
         class.  When the request is already present then it is first
@@ -99,6 +100,11 @@ public:
     */
     ::osl::Mutex& GetMutex (void);
 
+    /** Ensure we don't hand out a page deleted before anyone got a
+        chance to process it
+    */
+    virtual void PageInDestruction(const SdrPage& rPage);
+
 private:
     ::osl::Mutex maMutex;
     class Container;
-- 
1.8.4.2