From 211ac35314d661127c407635af880bcf1679ddba Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 4 Sep 2015 21:24:01 +0200 Subject: [PATCH] Work around crash on command line export This was a regression of 0c093a626472c7. The crash was found by the tex2lyx test case test-insets.tex: Running lyx -f main -e pdflatex test-insets.lyx.lyx did crash. This is not a real fix, but will do for now since previews are not needed in command line mode (I wonder why they are generated at all?) In the long term, we need theApp() to return a console application in commandline mode to eliminate the existing sifferences between export from GUI and commandline. --- src/graphics/PreviewLoader.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index cec05ed714..914d7d00d1 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -411,8 +411,13 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b) : parent_(p), buffer_(b), finished_generating_(true) { font_scaling_factor_ = int(buffer_.fontScalingFactor()); - fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16); - bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16); + if (theApp()) { + fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16); + bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16); + } else { + fg_color_ = 0x0; + bg_color_ = 0xffffff; + } if (!pconverter_) pconverter_ = setConverter("lyxpreview"); @@ -439,8 +444,12 @@ PreviewImage const * PreviewLoader::Impl::preview(string const & latex_snippet) const { int fs = int(buffer_.fontScalingFactor()); - int fg = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16); - int bg = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16); + int fg = 0x0; + int bg = 0xffffff; + if (theApp()) { + fg = strtol(theApp()->hexName(foregroundColor()).c_str(), 0, 16); + bg = strtol(theApp()->hexName(backgroundColor()).c_str(), 0, 16); + } if (font_scaling_factor_ != fs || fg_color_ != fg || bg_color_ != bg) { // Schedule refresh of all previews on zoom or color changes. // The previews are regenerated only after the zoom factor