Blame SOURCES/0006-fix-occasional-crash-on-dragging-and-dropping-pages-.patch

f0633d
From 152b0dd43165106f9c01bab33017e23dadf91fb6 Mon Sep 17 00:00:00 2001
f0633d
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
f0633d
Date: Thu, 12 Dec 2013 10:39:06 +0000
f0633d
Subject: [PATCH 6/9] fix occasional crash on dragging and dropping pages in
f0633d
 slidesorters
f0633d
f0633d
pages go into the cache, and sometimes they get deleted before the
f0633d
cache gets processed. Remove deleted pages when they go away
f0633d
f0633d
Change-Id: I291072a8541f4ca36979e9914975d81cc23a9497
f0633d
(cherry picked from commit abe9d1463282690313aaf91d2a54011d10b900b9)
f0633d
(cherry picked from commit 026e9335d792c6557255f064960e0ef6d28728e0)
f0633d
Reviewed-on: https://gerrit.libreoffice.org/7053
f0633d
Reviewed-by: David Tardon <dtardon@redhat.com>
f0633d
Tested-by: David Tardon <dtardon@redhat.com>
f0633d
---
f0633d
 sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx | 33 +++++++++++++++++++---
f0633d
 sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx | 12 ++++++--
f0633d
 2 files changed, 38 insertions(+), 7 deletions(-)
f0633d
f0633d
diff --git a/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx b/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
f0633d
index 835787b..cdc2b57 100644
f0633d
--- a/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
f0633d
+++ b/sd/source/ui/slidesorter/cache/SlsRequestQueue.cxx
f0633d
@@ -94,6 +94,7 @@ RequestQueue::RequestQueue (const SharedCacheContext& rpCacheContext)
f0633d
 
f0633d
 RequestQueue::~RequestQueue (void)
f0633d
 {
f0633d
+    Clear();
f0633d
 }
f0633d
 
f0633d
 
f0633d
@@ -120,7 +121,15 @@ void RequestQueue::AddRequest (
f0633d
     // order.
f0633d
     sal_Int32 nPriority (mpCacheContext->GetPriority(aKey));
f0633d
     Request aRequest (aKey, nPriority, eRequestClass);
f0633d
-    mpRequestQueue->insert(aRequest);
f0633d
+
f0633d
+    std::pair<Container::iterator,bool> ret = mpRequestQueue->insert(aRequest);
f0633d
+    bool bInserted = ret.second == true;
f0633d
+
f0633d
+    if (bInserted)
f0633d
+    {
f0633d
+        SdrPage *pPage = const_cast<SdrPage*>(aRequest.maKey);
f0633d
+        pPage->AddPageUser(*this);
f0633d
+    }
f0633d
 
f0633d
     SSCD_SET_REQUEST_CLASS(aKey,eRequestClass);
f0633d
 
f0633d
@@ -131,8 +140,11 @@ void RequestQueue::AddRequest (
f0633d
 #endif
f0633d
 }
f0633d
 
f0633d
-
f0633d
-
f0633d
+void RequestQueue::PageInDestruction(const SdrPage& rPage)
f0633d
+{
f0633d
+    //remove any requests pending for this page which is going away now
f0633d
+    RemoveRequest(&rPage);
f0633d
+}
f0633d
 
f0633d
 bool RequestQueue::RemoveRequest (
f0633d
     CacheKey aKey)
f0633d
@@ -152,7 +164,11 @@ bool RequestQueue::RemoveRequest (
f0633d
                 mnMinimumPriority++;
f0633d
             else if (aRequestIterator->mnPriorityInClass == mnMaximumPriority-1)
f0633d
                 mnMaximumPriority--;
f0633d
+
f0633d
+            SdrPage *pPage = const_cast<SdrPage*>(aRequestIterator->maKey);
f0633d
+            pPage->RemovePageUser(*this);
f0633d
             mpRequestQueue->erase(aRequestIterator);
f0633d
+
f0633d
             bRequestWasRemoved = true;
f0633d
 
f0633d
             if (bRequestWasRemoved)
f0633d
@@ -229,7 +245,10 @@ void RequestQueue::PopFront (void)
f0633d
     {
f0633d
         SSCD_SET_STATUS(maRequestQueue.begin()->mpData->GetPage(),NONE);
f0633d
 
f0633d
-        mpRequestQueue->erase(mpRequestQueue->begin());
f0633d
+        Container::const_iterator aIter(mpRequestQueue->begin());
f0633d
+        SdrPage *pPage = const_cast<SdrPage*>(aIter->maKey);
f0633d
+        pPage->RemovePageUser(*this);
f0633d
+        mpRequestQueue->erase(aIter);
f0633d
 
f0633d
         // Reset the priority counter if possible.
f0633d
         if (mpRequestQueue->empty())
f0633d
@@ -256,6 +275,12 @@ void RequestQueue::Clear (void)
f0633d
 {
f0633d
     ::osl::MutexGuard aGuard (maMutex);
f0633d
 
f0633d
+    for (Container::iterator aI = mpRequestQueue->begin(), aEnd = mpRequestQueue->end(); aI != aEnd; ++aI)
f0633d
+    {
f0633d
+        SdrPage *pPage = const_cast<SdrPage*>(aI->maKey);
f0633d
+        pPage->RemovePageUser(*this);
f0633d
+    }
f0633d
+
f0633d
     mpRequestQueue->clear();
f0633d
     mnMinimumPriority = 0;
f0633d
     mnMaximumPriority = 1;
f0633d
diff --git a/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx b/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
f0633d
index 78a4627..088a135 100644
f0633d
--- a/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
f0633d
+++ b/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx
f0633d
@@ -24,7 +24,8 @@
f0633d
 #include "cache/SlsCacheContext.hxx"
f0633d
 #include "taskpane/SlideSorterCacheDisplay.hxx"
f0633d
 #include <drawdoc.hxx>
f0633d
-#include "osl/mutex.hxx"
f0633d
+#include <osl/mutex.hxx>
f0633d
+#include <svx/sdrpageuser.hxx>
f0633d
 
f0633d
 
f0633d
 namespace sd { namespace slidesorter { namespace cache {
f0633d
@@ -34,11 +35,11 @@ class RequestData;
f0633d
 /** The request queue stores requests that are described by the RequestData
f0633d
     sorted according to priority class and then priority.
f0633d
 */
f0633d
-class RequestQueue
f0633d
+class RequestQueue : public sdr::PageUser
f0633d
 {
f0633d
 public:
f0633d
     RequestQueue (const SharedCacheContext& rpCacheContext);
f0633d
-    ~RequestQueue (void);
f0633d
+    virtual ~RequestQueue();
f0633d
 
f0633d
     /** Insert a request with highest or lowest priority in its priority
f0633d
         class.  When the request is already present then it is first
f0633d
@@ -99,6 +100,11 @@ public:
f0633d
     */
f0633d
     ::osl::Mutex& GetMutex (void);
f0633d
 
f0633d
+    /** Ensure we don't hand out a page deleted before anyone got a
f0633d
+        chance to process it
f0633d
+    */
f0633d
+    virtual void PageInDestruction(const SdrPage& rPage);
f0633d
+
f0633d
 private:
f0633d
     ::osl::Mutex maMutex;
f0633d
     class Container;
f0633d
-- 
f0633d
1.8.4.2
f0633d