Martin Vermeer wrote:
> Here's the patch.

And I understand how it is triggered. We have a sort of 'race' 
condition between the destruction of two static variables.

In gettext.C:
Messages & getLyXMessages() {
        static Messages lyx_messages;
        return lyx_messages;
}

In Dialogs.C
namespace {
BugfixSignal<boost::signal2<void, string const &, InsetBase*> >
        hideSignal;
}

It just so happens that on my box, hideSignal is destroyed before 
lyx_messages. On your box the converse is true.

(Note for Lars: the Dialogs hide member function is a static function. 
It is invoked when the inset is destroyed and should hide the inset's 
dialog in all LyXViews. So this is correct IMO.)

So, what triggers the bug/crash. The (stupid) creation of dialogs 
unnecessarily when LyXView::getDialogs() is invoked to hide() or 
update() dialogs that are not visible and indeed haven't ever been 
visible because they haven't been created.

So, IMO, the proper fix is not to build the dialogs in such cases.

Your patch is essentially a work around to fix this breakage. It does 
fix the immediate problem because the Dialogs::find member function 
will cause the named dialog to be created (calls its constructor) but 
does not go on to call one of the other FormXYZ member functions 
where your patch re-positions the _(...) call.

So, now that we understand what is happening, I think we should ditch 
your patch and apply mine. Yours is a work around broken behaviour. 
Mine cures the source of the breakage.

Thoughts?
Angus


-- 
Angus
Index: src/frontends/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/ChangeLog,v
retrieving revision 1.225
diff -u -p -r1.225 ChangeLog
--- src/frontends/ChangeLog	15 Sep 2003 15:20:16 -0000	1.225
+++ src/frontends/ChangeLog	15 Sep 2003 20:47:46 -0000
@@ -1,5 +1,12 @@
 2003-09-15  Angus Leeming  <[EMAIL PROTECTED]>
 
+	* Dialogs.[Ch] (find): renamed as find_or_build.
+	(update, hideSlot): don't call find_or_build to find the requested dialog.
+	Instead, search dialogs_, the list of already constructed dialogs. If it
+	ain't found, do nothing.
+
+2003-09-15  Angus Leeming  <[EMAIL PROTECTED]>
+
 	* Painter.C: add #include "LColor.h".
 	(rectText): pass EnumLColor args, rather than LColor::color ones.
 
Index: src/frontends/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Dialogs.C,v
retrieving revision 1.28
diff -u -p -r1.28 Dialogs.C
--- src/frontends/Dialogs.C	5 Sep 2003 10:55:42 -0000	1.28
+++ src/frontends/Dialogs.C	15 Sep 2003 20:47:46 -0000
@@ -75,7 +75,7 @@ Dialogs::Dialogs(LyXView & lyxview)
 }
 
 
-Dialog * Dialogs::find(string const & name)
+Dialog * Dialogs::find_or_build(string const & name)
 {
 	if (!isValidName(name))
 		return 0;
@@ -83,18 +83,17 @@ Dialog * Dialogs::find(string const & na
 	std::map<string, DialogPtr>::iterator it =
 		dialogs_.find(name);
 
-	if (it == dialogs_.end()) {
-		dialogs_[name] = DialogPtr(build(name));
-		return dialogs_[name].get();
-	}
+	if (it != dialogs_.end())
+		return it->second.get();
 
-	return it->second.get();
+	dialogs_[name] = DialogPtr(build(name));
+	return dialogs_[name].get();
 }
 
 
 void Dialogs::show(string const & name, string const & data)
 {
-	Dialog * dialog = find(name);
+	Dialog * dialog = find_or_build(name);
 	if (!dialog)
 		return;
 
@@ -105,7 +104,7 @@ void Dialogs::show(string const & name, 
 
 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
 {
-	Dialog * dialog = find(name);
+	Dialog * dialog = find_or_build(name);
 	if (!dialog)
 		return;
 
@@ -127,10 +126,12 @@ bool Dialogs::visible(string const & nam
 
 void Dialogs::update(string const & name, string const & data)
 {
-	Dialog * dialog = find(name);
-	if (!dialog)
+	std::map<string, DialogPtr>::const_iterator it =
+		dialogs_.find(name);
+	if (it == dialogs_.end())
 		return;
 
+	Dialog * const dialog = it->second.get();
 	if (dialog->isVisible())
 		dialog->update(data);
 }
@@ -138,13 +139,15 @@ void Dialogs::update(string const & name
 
 void Dialogs::hideSlot(string const & name, InsetBase * inset)
 {
-	Dialog * dialog = find(name);
-	if (!dialog)
+	std::map<string, DialogPtr>::const_iterator it =
+		dialogs_.find(name);
+	if (it == dialogs_.end())
 		return;
 
 	if (inset && inset != getOpenInset(name))
 		return;
 
+	Dialog * const dialog = it->second.get();
 	if (dialog->isVisible())
 		dialog->hide();
 	open_insets_[name] = 0;
Index: src/frontends/Dialogs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Dialogs.h,v
retrieving revision 1.90
diff -u -p -r1.90 Dialogs.h
--- src/frontends/Dialogs.h	7 Sep 2003 21:25:33 -0000	1.90
+++ src/frontends/Dialogs.h	15 Sep 2003 20:47:46 -0000
@@ -132,7 +132,7 @@ private:
 	///
 	bool isValidName(string const & name) const;
 	///
-	Dialog * find(string const & name);
+	Dialog * find_or_build(string const & name);
 	///
 	Dialog * build(string const & name);
 

Reply via email to