On Tue, Jun 30, 2015 at 06:55:04PM +0200, Enrico Forestieri wrote:
> commit 305a712bbb1c201416e7bed2d8e6b7362c3aa5d5
> Author: Enrico Forestieri <for...@lyx.org>
> Date:   Tue Jun 30 18:54:19 2015 +0200
> 
>     Avoid using a dangling pointer
>     
>     This can happen when a macro is copied and then the document where
>     it is defined is closed. In this case, the macro survives in the
>     cut stack but the the buffer pointer is dangling.

Richard, this is also needed in stable to avoid a crash that can be
triggered as follows:
1) With instant preview off, load the attached file1.lyx and file2.lyx
2) In file2.lyx, select and copy the math inset, then close file2.lyx
3) Now activate instant preview for math

It might not crash on the first try but eventually will do.
I am also attaching the corresponding patch for stable.

-- 
Enrico
diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index ed28927..491b75d 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -22,6 +22,7 @@
 #include "MathSupport.h"
 
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "Cursor.h"
@@ -180,7 +181,10 @@ void MathMacro::assign(MathMacro const & that)
                // We need to update macro_ by ourselves because in this case
                // MathData::metrics() is not called when selecting a math inset
                DocIterator const & pos = macroBackup_.pos();
-               macro_ = pos.buffer() ? pos.buffer()->getMacro(name(), pos) : 0;
+               Buffer const * buf = pos.buffer();
+               if (buf && !theBufferList().isLoaded(buf))
+                       buf = 0;
+               macro_ = buf ? buf->getMacro(name(), pos) : 0;
                if (!macro_)
                        macro_ = &macroBackup_;
        }
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\begin_inset Formula $\Mapsto$
\end_inset


\end_layout

\end_body
\end_document
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding default
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format pdf2
\output_sync 0
\output_sync_macro "\synctex=-1"
\bibtex_command default
\index_command default
\float_placement tp
\paperfontsize default
\spacing single
\use_hyperref false
\pdf_bookmarks false
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 2
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle false
\papersize a4paper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 2
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle plain
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\begin_inset FormulaMacro
\newcommand{\foo}[1]{#1}
\end_inset


\end_layout

\begin_layout Standard
\begin_inset Formula $\foo{bar}$
\end_inset


\end_layout

\end_body
\end_document

Reply via email to