drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx |   
19 ++++++----
 drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx      |   
19 ++++++----
 2 files changed, 26 insertions(+), 12 deletions(-)

New commits:
commit aa3bca30248436d051981c6fff03c864d0228874
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Fri Dec 29 21:36:10 2023 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Tue Jan 2 15:05:50 2024 +0100

    Add flush mechanism to buffered Primitives IV
    
    Now trying not to delete a LocalCallbackTimer if it gets
    used - no limitation since this only happens when a
    time is given (maCallbackSeconds).
    Also added to reset callback ptr (clearCallback()) to
    nullptr and make onShot dependent of that, hope is that
    destruction of LocalCallbackTimer in
    ~BufferedDecompositionPrimitive2D gets safer that way,
    excluding race conditions.
    
    Change-Id: Id474962bdae14631afc42d2d92db635408fb67d9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161434
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git 
a/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx 
b/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx
index 537a0106d80d..96fd72eb25ca 100644
--- a/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx
+++ b/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx
@@ -36,11 +36,17 @@ public:
     {
     }
 
+    void clearCallback() { pCustomer = nullptr; }
+
 protected:
     virtual void SAL_CALL onShot() override;
 };
 
-void SAL_CALL LocalCallbackTimer::onShot() { 
flushBufferedDecomposition(*pCustomer); }
+void SAL_CALL LocalCallbackTimer::onShot()
+{
+    if (nullptr != pCustomer)
+        flushBufferedDecomposition(*pCustomer);
+}
 }
 
 namespace drawinglayer::primitive2d
@@ -55,7 +61,7 @@ 
BufferedDecompositionGroupPrimitive2D::getBuffered2DDecomposition() const
 {
     if (0 != maCallbackSeconds && maCallbackTimer.is())
     {
-        // decomposition was used, touch
+        // decomposition was used, touch/restart time
         
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
     }
 
@@ -70,19 +76,20 @@ void 
BufferedDecompositionGroupPrimitive2D::setBuffered2DDecomposition(Primitive
         {
             if (rNew.empty())
             {
-                // no more decomposition, end callback
+                // stop timer
                 maCallbackTimer->stop();
-                maCallbackTimer.clear();
             }
             else
             {
                 // decomposition changed, touch
                 
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
+                if (!maCallbackTimer->isTicking())
+                    maCallbackTimer->start();
             }
         }
         else if (!rNew.empty())
         {
-            // decomposition changed, start callback
+            // decomposition defined/set/changed, init & start timer
             maCallbackTimer.set(new LocalCallbackTimer(*this));
             
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
             maCallbackTimer->start();
@@ -105,8 +112,8 @@ 
BufferedDecompositionGroupPrimitive2D::~BufferedDecompositionGroupPrimitive2D()
     if (maCallbackTimer.is())
     {
         // no more decomposition, end callback
+        
static_cast<LocalCallbackTimer*>(maCallbackTimer.get())->clearCallback();
         maCallbackTimer->stop();
-        maCallbackTimer.clear();
     }
 }
 
diff --git 
a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx 
b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx
index 0ed22120c6d6..c7f3b78477b0 100644
--- a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx
+++ b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx
@@ -36,11 +36,17 @@ public:
     {
     }
 
+    void clearCallback() { pCustomer = nullptr; }
+
 protected:
     virtual void SAL_CALL onShot() override;
 };
 
-void SAL_CALL LocalCallbackTimer::onShot() { 
flushBufferedDecomposition(*pCustomer); }
+void SAL_CALL LocalCallbackTimer::onShot()
+{
+    if (nullptr != pCustomer)
+        flushBufferedDecomposition(*pCustomer);
+}
 }
 
 namespace drawinglayer::primitive2d
@@ -54,7 +60,7 @@ const Primitive2DContainer& 
BufferedDecompositionPrimitive2D::getBuffered2DDecom
 {
     if (0 != maCallbackSeconds && maCallbackTimer.is())
     {
-        // decomposition was used, touch
+        // decomposition was used, touch/restart time
         
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
     }
 
@@ -69,19 +75,20 @@ void 
BufferedDecompositionPrimitive2D::setBuffered2DDecomposition(Primitive2DCon
         {
             if (rNew.empty())
             {
-                // no more decomposition, end callback
+                // stop timer
                 maCallbackTimer->stop();
-                maCallbackTimer.clear();
             }
             else
             {
                 // decomposition changed, touch
                 
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
+                if (!maCallbackTimer->isTicking())
+                    maCallbackTimer->start();
             }
         }
         else if (!rNew.empty())
         {
-            // decomposition changed, start callback
+            // decomposition defined/set/changed, init & start timer
             maCallbackTimer.set(new LocalCallbackTimer(*this));
             
maCallbackTimer->setRemainingTime(salhelper::TTimeValue(maCallbackSeconds, 0));
             maCallbackTimer->start();
@@ -104,8 +111,8 @@ 
BufferedDecompositionPrimitive2D::~BufferedDecompositionPrimitive2D()
     if (maCallbackTimer.is())
     {
         // no more decomposition, end callback
+        
static_cast<LocalCallbackTimer*>(maCallbackTimer.get())->clearCallback();
         maCallbackTimer->stop();
-        maCallbackTimer.clear();
     }
 }
 

Reply via email to