Am Montag, dem 01.11.2021 um 14:15 +0100 schrieb Pavel Sanda:
> Looking at the backtrace and commit it seems that 
> +         TocItem const & item =
> +                 gui_view_.tocModels().currentItem(current_type_,
> index);
> triggers the crash.
> 
> Juergen, can you reproduce?

Yes. I am not sure what goes on here exactly, but the toc seems empty
after the window switch. I don't think the code above is to blame, it
just reveals the problem.

The attached patch prevents the crash, but I am not sure whether it
doesn't hide the actual problem. Do we need to update the respective
toc somewhere? But where?

Jürgen

diff --git a/src/frontends/qt/TocModel.cpp b/src/frontends/qt/TocModel.cpp
index 16990b8359..c0c3dce548 100644
--- a/src/frontends/qt/TocModel.cpp
+++ b/src/frontends/qt/TocModel.cpp
@@ -327,6 +327,11 @@ TocItem const TocModels::currentItem(QString const & type,
 	}
 	LASSERT(index.model() == it.value()->model(), return TocItem());
 
+	if (it.value()->empty()) {
+		LYXERR(Debug::GUI, "TocModels::currentItem(): requested toc is empty!");
+		return TocItem();
+	}
+
 	return it.value()->tocItem(index);
 }
 
diff --git a/src/frontends/qt/TocModel.h b/src/frontends/qt/TocModel.h
index 55507a0a92..ee447616d0 100644
--- a/src/frontends/qt/TocModel.h
+++ b/src/frontends/qt/TocModel.h
@@ -47,6 +47,8 @@ public:
 	///
 	void clear();
 	///
+	bool empty() { return toc_->empty(); }
+	///
 	QAbstractItemModel * model();
 	///
 	QAbstractItemModel const * model() const;

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to