Georg Baum wrote:
> We still have some crashes related to open dialogs, see
> http://bugzilla.lyx.org/show_bug.cgi?id=1879. The attached patch should
> fix them. I am now pretty sure that I understand LFUN_INSET_MODIFY: The
> arguments are the new inset parameters. For many insets the first
> parameter is thee inset name, but not for all. So it is safe to accept
> LFUN_INSET_MODIFY in InsetBase::getStatus() unconditionally.
> The other changes are some leftovers from my last patch. This is going in
> tomorrow unless somebody objects.
I applied that now, but it was not the whole fix. It only moved the crash,
we have a more general problem here: The Dialogs class stores a InsetBase *
for every open dialog. If you delete an inset while the dialog is open the
pointer does still exist, but is not valid anymore.
Storing a pointer in frontend code while all other fronted-core-interaction
uses strings is no clean design IMHO.
A proof-of-concept fix is attached. It works only for "normal" delete (the
inset must not be selected, and the deletion must not cause a paragraph
merge. BTW, Dialogs::hideSlot() is currently not used.
Does anybody have an idea what to do now?
Georg
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.601
diff -u -p -r1.601 text.C
--- src/text.C 5 May 2005 18:33:47 -0000 1.601
+++ src/text.C 17 May 2005 13:33:28 -0000
@@ -48,8 +48,8 @@
#include "rowpainter.h"
#include "undo.h"
#include "vspace.h"
-#include "WordLangTuple.h"
+#include "frontends/Dialogs.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
@@ -1624,6 +1625,15 @@ void LyXText::backspace(LCursor & cur)
// without the dreaded mechanism. (JMarc)
setCursorIntern(cur, cur.pit(), cur.pos() - 1,
false, cur.boundary());
+ InsetBase * const inset = cur.paragraph().getInset(cur.pos());
+ if (inset) {
+ // Hide the dialog if it is open to prevent crashes
+ // FIXME: This should not be here, maybe in the inset destructor
+ // FIXME: We need the mailer name, but this is not available here.
+ // In most (all?) cases it is the inset name in lower case.
+ string const name = lyx::support::ascii_lowercase(inset->getInsetName());
+ cur.bv().owner()->getDialogs().hideSlot(name, inset);
+ }
cur.paragraph().erase(cur.pos());
}
Index: src/frontends/Dialogs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Dialogs.h,v
retrieving revision 1.108
diff -u -p -r1.108 Dialogs.h
--- src/frontends/Dialogs.h 13 Apr 2005 09:43:57 -0000 1.108
+++ src/frontends/Dialogs.h 17 May 2005 13:33:29 -0000
@@ -105,9 +105,9 @@ public:
void disconnect(std::string const & name);
///
InsetBase * getOpenInset(std::string const & name) const;
-private:
///
void hideSlot(std::string const & name, InsetBase * inset);
+private:
///
void redraw() const;
///