On Mon, Sep 12, 2016 at 05:01:33AM +0200, Enrico Forestieri wrote:

> On Sun, Sep 11, 2016 at 09:04:56PM +0100, Guillaume Munch wrote:
> > Le 11/09/2016 à 11:05, Enrico Forestieri a écrit :
> > 
> > >Please give
> > >steps or test cases for reproducing the crash and I will have a look.
> > >
> > 
> > It usually takes some effort. I'll try to find the time.
> 
> You can spare your time as I think I found the problem. The patch simply
> uncovered a latent bug. The crash only occurs when there is a user
> defined math macro. In this case, d->macro_->symbol() may return bogus
> values. For a user defined macro it should always return a null pointer,
> but for unknown reasons it sometimes returns strange values, which are
> clearly bogus and cause a crash when dereferenced.
> 
> I did not succeed in understanding why this occurs. Simply left clicking
> here and there can trigger the crash. Not always, but insisting long
> enough it eventually occurs.
> 
> The attached patch solves the issue for me. It is not ideal because it
> simply covers the real bug. When a user defined macro is detected, the
> value returned by d->macro_->symbol() is simply not used, as in this
> case we know what to do.
> 
> Please test if you find the time.

Please, attached find an updated patch that also accounts for latex
macros defined in ERT.

-- 
Enrico
diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index 4529cf9..cb853a3 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -614,7 +614,8 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                drawMarkers2(pi, expx, expy);
        } else {
                bool drawBox = lyxrc.macro_edit_style == 
LyXRC::MACRO_EDIT_INLINE_BOX;
-               bool upshape = d->macro_ && d->macro_->symbol()
+               bool user_macro = mathedWordList().find(name()) == 
mathedWordList().end();
+               bool upshape = user_macro ? false : d->macro_ && 
d->macro_->symbol()
                                && d->macro_->symbol()->extra == "textmode";
                Changer dummy = pi.base.font.changeShape(upshape ? UP_SHAPE
                                                        : pi.base.font.shape());
@@ -929,9 +930,10 @@ bool MathMacro::folded() const
 
 void MathMacro::write(WriteStream & os) const
 {
-       bool const textmode_macro = d->macro_ && d->macro_->symbol()
+       bool user_macro = mathedWordList().find(name()) == 
mathedWordList().end();
+       bool textmode_macro = user_macro ? false : d->macro_ && 
d->macro_->symbol()
                                && d->macro_->symbol()->extra == "textmode";
-       bool const needs_mathmode = d->macro_ && (!d->macro_->symbol()
+       bool needs_mathmode = user_macro ? bool(d->macro_) : d->macro_ && 
(!d->macro_->symbol()
                                || d->macro_->symbol()->extra != "textmode");
 
        MathEnsurer ensurer(os, needs_mathmode, true, textmode_macro);

Reply via email to