[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - desktop/source libreofficekit/qa
Jan Holesovsky
kendy at collabora.com
Mon Mar 20 22:10:13 UTC 2017
desktop/source/lib/init.cxx | 24 ++++++++++++++++++----
libreofficekit/qa/unit/tiledrendering.cxx | 32 ++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 4 deletions(-)
New commits:
commit 8b446be53930bc847d45b0b6f60f9f47d39cd88c
Author: Jan Holesovsky <kendy at collabora.com>
Date: Mon Mar 20 23:05:22 2017 +0100
lok: Fix crash in paintPartTile() when the current view was destroyed.
Change-Id: I59b71ee6815cbcfa4c8b5f68ae6dc9299856d49e
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 54c1bf2b2960..597a225f20b2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1631,11 +1631,27 @@ void doc_paintPartTile(LibreOfficeKitDocument* pThis,
<< nTilePosX << ", " << nTilePosY << ") to ["
<< nCanvasWidth << "x" << nCanvasHeight << "]px" );
- // Disable callbacks while we are painting.
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
- const int nOrigViewId = doc_getView(pThis);
+ int nOrigViewId = doc_getView(pThis);
+
+ if (nOrigViewId < 0)
+ {
+ // tile painting always needs a SfxViewShell::Current(), but actually
+ // it does not really matter which one - all of them should paint the
+ // same thing.
+ int viewCount = doc_getViewsCount(pThis);
+ if (viewCount == 0)
+ return;
- if (nOrigViewId >= 0)
+ std::vector<int> viewIds(viewCount);
+ doc_getViewIds(pThis, viewIds.data(), viewCount);
+
+ nOrigViewId = viewIds[0];
+ doc_setView(pThis, nOrigViewId);
+ }
+
+ // Disable callbacks while we are painting.
+ if (nOrigViewId >= 0 && pDocument->mpCallbackFlushHandlers[nOrigViewId])
pDocument->mpCallbackFlushHandlers[nOrigViewId]->setPartTilePainting(true);
try
@@ -1686,7 +1702,7 @@ void doc_paintPartTile(LibreOfficeKitDocument* pThis,
// Nothing to do but restore the PartTilePainting flag.
}
- if (nOrigViewId >= 0)
+ if (nOrigViewId >= 0 && pDocument->mpCallbackFlushHandlers[nOrigViewId])
pDocument->mpCallbackFlushHandlers[nOrigViewId]->setPartTilePainting(false);
}
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index e28fece0d8cb..0a93c4651d77 100644
--- a/libreofficekit/qa/unit/tiledrendering.cxx
+++ b/libreofficekit/qa/unit/tiledrendering.cxx
@@ -66,6 +66,7 @@ public:
void testDocumentTypes( Office* pOffice );
void testImpressSlideNames( Office* pOffice );
void testCalcSheetNames( Office* pOffice );
+ void testPaintPartTile( Office* pOffice );
#if 0
void testOverlay( Office* pOffice );
#endif
@@ -92,6 +93,7 @@ void TiledRenderingTest::runAllTests()
testDocumentTypes( pOffice.get() );
testImpressSlideNames( pOffice.get() );
testCalcSheetNames( pOffice.get() );
+ testPaintPartTile( pOffice.get() );
#if 0
testOverlay( pOffice.get() );
#endif
@@ -180,6 +182,36 @@ void TiledRenderingTest::testCalcSheetNames( Office* pOffice )
CPPUNIT_ASSERT( strcmp( pDocument->getPartName( 2 ), "Sheet3" ) == 0 );
}
+void TiledRenderingTest::testPaintPartTile(Office* pOffice)
+{
+ const string sTextDocPath = m_sSrcRoot + "/libreofficekit/qa/data/blank_text.odt";
+ const string sTextLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.blank_text.odt#";
+
+ // FIXME: same comment as below wrt lockfile removal.
+ remove(sTextLockFile.c_str());
+
+ std::unique_ptr<Document> pDocument(pOffice->documentLoad( sTextDocPath.c_str()));
+ CPPUNIT_ASSERT(pDocument.get());
+ CPPUNIT_ASSERT_EQUAL(LOK_DOCTYPE_TEXT, static_cast<LibreOfficeKitDocumentType>(pDocument->getDocumentType()));
+
+ // Create two views.
+ pDocument->getView();
+ pDocument->createView();
+
+ int nView2 = pDocument->getView();
+
+ // Destroy the current view
+ pDocument->destroyView(nView2);
+
+ int nCanvasWidth = 256;
+ int nCanvasHeight = 256;
+ std::vector<unsigned char> aBuffer(nCanvasWidth * nCanvasHeight * 4);
+
+ // And try to paintPartTile() - this used to crash when the current viewId
+ // was destroyed
+ pDocument->paintPartTile(aBuffer.data(), /*nPart=*/0, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
+}
+
#if 0
static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
const int nWidth, const int nHeight )
More information about the Libreoffice-commits
mailing list