Commit 04bf8b65 authored by Christoph Cullmann's avatar Christoph Cullmann 🍨
Browse files

avoid crashing one some empty viewspace variants

adding tests for these cases, too
one needs both checks, each test triggers a different assert
or crash
parent ed2e1ba1
Pipeline #230604 passed with stage
in 5 minutes and 45 seconds
......@@ -136,3 +136,37 @@ void KateViewManagementTests::testMoveViewBetweenViewspaces()
QCOMPARE(vm->m_viewSpaceList.size(), 1);
QCOMPARE(vm->m_views.size(), 2);
}
void KateViewManagementTests::testTwoMainWindowsCloseInitialDocument1()
{
// get first main window
KateMainWindow *first = app->activeKateMainWindow();
QVERIFY(first);
// create a second one
KateMainWindow *second = app->newMainWindow();
QVERIFY(second);
// close the initial document
QVERIFY(app->closeDocument(first->viewManager()->activeView()->document()));
// create a new document, this did crash due to empty view space
second->viewManager()->slotDocumentNew();
}
void KateViewManagementTests::testTwoMainWindowsCloseInitialDocument2()
{
// get first main window
KateMainWindow *first = app->activeKateMainWindow();
QVERIFY(first);
// create a second one
KateMainWindow *second = app->newMainWindow();
QVERIFY(second);
// close the initial document tab in second window
second->viewManager()->activeViewSpace()->closeDocument(first->viewManager()->activeView()->document());
// create a new document, this did crash due to empty view space
second->viewManager()->slotDocumentNew();
}
......@@ -28,6 +28,8 @@ private Q_SLOTS:
void testViewspaceClosesWhenLastViewClosed();
void testViewspaceClosesWhenThereIsWidget();
void testMoveViewBetweenViewspaces();
void testTwoMainWindowsCloseInitialDocument1();
void testTwoMainWindowsCloseInitialDocument2();
private:
class QTemporaryDir *m_tempdir;
......
......@@ -346,9 +346,11 @@ KTextEditor::View *KateViewSpace::createView(KTextEditor::Document *doc)
void KateViewSpace::removeView(KTextEditor::View *v)
{
// remove view mappings
auto it = m_docToView.find(v->document());
Q_ASSERT(it != m_docToView.end());
// remove view mappings, if we have none, this document didn't have any view here at all, just ignore it
const auto it = m_docToView.find(v->document());
if (it == m_docToView.end()) {
return;
}
m_docToView.erase(it);
// ...and now: remove from view space
......@@ -670,11 +672,13 @@ void KateViewSpace::documentDestroyed(QObject *doc)
{
/**
* WARNING: this pointer is half destroyed
* only good enough to check pointer value e.g. for hashs
* only good enough to check pointer value e.g. for hashes
*/
KTextEditor::Document *invalidDoc = static_cast<KTextEditor::Document *>(doc);
Q_ASSERT(m_registeredDocuments.contains(invalidDoc));
m_registeredDocuments.removeAll(invalidDoc);
if (m_registeredDocuments.removeAll(invalidDoc) == 0) {
// do nothing if this document wasn't registered for this viewspace
return;
}
/**
* we shall have no views for this document at this point in time!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment