[LyX/master] InsetText::docbookRenderAsImage: don't crash when previewing the image fails.

Thibaut Cuvelier <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 5a2acebd58fc4477e1f437f845a4ce981108a4c4
Author: Thibaut Cuvelier <[email protected]>
Date:   Fri Mar 6 19:19:30 2026 +0100

    InsetText::docbookRenderAsImage: don't crash when previewing the image fails.
    
    It's happening when LyX has no LaTeX configured when exporting export/examples/ja/Modules/Linguistics as DocBook.
---
 src/insets/InsetText.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 04a71cb3f8..6e5b97fdaa 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -689,7 +689,7 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH
 	// Also, the image must be generated before the DocBook output is finished,
 	// unlike a preview that is not immediately required for display.
 	docstring const latex_snippet = insetToLaTeXSnippet(&buffer(), this);
-	docstring const snippet = support::trim(latex_snippet);
+	docstring const snippet = trim(latex_snippet);
 	// TODO: no real support for Unicode. This code is very similar to RenderPreview::addPreview, the same gotcha applies.
 
 	graphics::PreviewLoader* loader = buffer().loader();
@@ -698,8 +698,14 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH
 	loader->add(snippet);
 	loader->startLoading(true); // Generate the image and wait until done.
 	graphics::PreviewImage const * img = loader->preview(snippet);
-	LASSERT(img != nullptr, return);
-	support::FileName const & filename = img->filename();
+	if (!img) {
+		xs << XMLStream::ESCAPE_NONE << "<!-- Exporting a figure as image failed. -->";
+		xs << XMLStream::ESCAPE_NONE << "<!-- ";
+		xs << latex_snippet;
+		xs << XMLStream::ESCAPE_NONE << " -->";
+		return;
+	}
+	FileName const & filename = img->filename();
 
 	// Use a file name that is only determined by the LaTeX code: the name of
 	// the snippet is more or less random (i.e., if the user generates the file
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.