Abdelrazak Younes wrote:
This happens while trying to open any of the help documents.

Richard maybe?

OK. This was caused by my commits---so my bad---but I think it's because I exposed an underlying bug. I've fixed it for now, in the sense that the help documents will open. The problem was that InsetCollapsable::layout_ had not been set before we entered InsetText::read(), and so the call to InsetCollapsable::isFreeSpacing(), viz
   return layout_->freespacing;
crashes because of the null pointer. The easy solution is to set it first. This wasn't a problem before, because this code:
bool Paragraph::isFreeSpacing() const
{
   if (d->layout_->free_spacing)
       return true;
   return d->inset_owner_ && d->inset_owner_->isFreeSpacing();
}
would return false when d->inset_owner_ didn't exit. But that's just wrong in certain cases, in particular, when the inset in question allows free spacing.

But the problem runs deeper. Look at this code:
void InsetCollapsable::setLayout(TextClassPtr tc)
{
   textClass_ = tc;
   if ( tc.get() != 0 ) {
       layout_ = &tc->insetlayout(name());
       labelstring_ = layout_->labelstring;
   } else {
       layout_ = 0;
       labelstring_ = _("UNDEFINED");
   }

   setButtonLabel();
}
It looks to me like there are cases here where we could end up with a null layout_ pointer. To some extent, this can be addressed by changing the routines that try to consult layout_.

What we need here seems to me to be a hardcoded empty InsetLayout, similar to the hardcoded empty layout introduced into TextClass. This already kind of exists in TextClass::insetlayout(), though it isn't available if we don't have a TextClass. So I've made it static in the attached patch and changed a few related things along the way. Comments welcome.

Richard

Index: TextClass.cpp
===================================================================
--- TextClass.cpp	(revision 23079)
+++ TextClass.cpp	(working copy)
@@ -133,6 +133,9 @@
 docstring const TextClass::emptylayout_ = from_ascii("PlainLayout");
 
 
+InsetLayout TextClass::empty_insetlayout_;
+
+
 bool TextClass::isTeXClassAvailable() const
 {
 	return texClassAvail_;
@@ -1168,12 +1171,7 @@
 			break;
 		n = n.substr(0,i);
 	}
-	static InsetLayout empty;
-	empty.labelstring = from_utf8("UNDEFINED");
-	empty.labelfont = sane_font;
-	empty.labelfont.setColor(Color_error);
-	empty.bgcolor = Color_error;
-	return empty;
+	return empty_insetlayout_;
 }
 
 
Index: insets/InsetFlex.cpp
===================================================================
--- insets/InsetFlex.cpp	(revision 23079)
+++ insets/InsetFlex.cpp	(working copy)
@@ -61,12 +61,6 @@
 }
 
 
-bool InsetFlex::undefined() const
-{
-	return getLayout().labelstring == from_utf8("UNDEFINED");
-}
-
-
 docstring const InsetFlex::editMessage() const
 {
 	return _("Opened Flex Inset");
Index: insets/InsetLayout.h
===================================================================
--- insets/InsetLayout.h	(revision 23079)
+++ insets/InsetLayout.h	(working copy)
@@ -23,6 +23,12 @@
 ///
 class InsetLayout {
 public:
+	InsetLayout() : 
+		name("undefined"),
+		labelstring(from_utf8("UNDEFINED")),
+		font(sane_font), labelfont(sane_font),
+		bgcolor(Color_error)
+		{ labelfont.setColor(Color_error); };
 	std::string name;
 	std::string lyxtype;
 	docstring labelstring;
Index: insets/InsetCollapsable.cpp
===================================================================
--- insets/InsetCollapsable.cpp	(revision 23081)
+++ insets/InsetCollapsable.cpp	(working copy)
@@ -132,7 +132,7 @@
 		layout_ = &tc->insetlayout(name());
 		labelstring_ = layout_->labelstring;
 	} else {
-		layout_ = 0;
+		layout_ = &TextClass::emptyInsetLayout();
 		labelstring_ = _("UNDEFINED");
 	}
 
@@ -885,4 +885,11 @@
 }
 
 
+bool InsetCollapsable::undefined() const
+{
+	std::string const & n = getLayout().name;
+	return n.empty() || n == TextClass::emptyInsetLayout().name;
+}
+
+
 } // namespace lyx
Index: insets/InsetFlex.h
===================================================================
--- insets/InsetFlex.h	(revision 23079)
+++ insets/InsetFlex.h	(working copy)
@@ -31,9 +31,6 @@
 	///
 	docstring name() const { return from_utf8(name_); }
 
-	/// Is this character style defined in the document's textclass?
-	/// May be wrong after textclass change or paste from another document
-	bool undefined() const;
 	///
 	virtual docstring const editMessage() const;
 	///
Index: insets/InsetCollapsable.h
===================================================================
--- insets/InsetCollapsable.h	(revision 23079)
+++ insets/InsetCollapsable.h	(working copy)
@@ -161,7 +161,9 @@
 	virtual bool forceLTR() const { return layout_->forceltr; }
 	///
 	virtual bool useEmptyLayout() const { return true; }
-
+	/// Is this inset's layout defined in the document's textclass?
+	/// May be wrong after textclass change or paste from another document
+	bool undefined() const;
 protected:
 	///
 	virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
Index: TextClass.h
===================================================================
--- TextClass.h	(revision 23079)
+++ TextClass.h	(working copy)
@@ -182,6 +182,8 @@
 	int max_toclevel() const;
 	/// returns true if the class has a ToC structure
 	bool hasTocLevels() const;
+	///
+	static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
 private:
 	///
 	bool deleteLayout(docstring const &);
@@ -265,6 +267,8 @@
 	int min_toclevel_;
 	/// The maximal TocLevel of sectioning layouts
 	int max_toclevel_;
+	///
+	static InsetLayout empty_insetlayout_;
 };
 
 
Index: CutAndPaste.cpp
===================================================================
--- CutAndPaste.cpp	(revision 23079)
+++ CutAndPaste.cpp	(working copy)
@@ -449,7 +449,7 @@
 			// FIXME: Should we verify all InsetCollapsable?
 			continue;
 		inset->setLayout(newone);
-		if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
+		if (!inset->undefined())
 			continue;
 		// The flex inset is undefined in newtc
 		docstring const s = bformat(_(

Reply via email to