merge fix for save file error
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index f8683aa..af8ba5f 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -2300,8 +2300,11 @@
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
{
- const XMLElement* parentElem = element.Parent()->ToElement();
- bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
+ const XMLElement* parentElem = NULL;
+ if ( element.Parent() ) {
+ parentElem = element.Parent()->ToElement();
+ }
+ bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
OpenElement( element.Name(), compactMode );
while ( attribute ) {
PushAttribute( attribute->Name(), attribute->Value() );
diff --git a/xmltest.cpp b/xmltest.cpp
index 09c781e..3fef541 100644
--- a/xmltest.cpp
+++ b/xmltest.cpp
@@ -1426,13 +1426,20 @@
doc.Print( &printer );
}
{
+ // Issue 299. Can print elements that are not linked in.
+ // Will crash if issue not fixed.
+ XMLDocument doc;
+ XMLElement* newElement = doc.NewElement( "printme" );
+ XMLPrinter printer;
+ newElement->Accept( &printer );
+ }
+ {
// Issue 302. Clear errors from LoadFile/SaveFile
XMLDocument doc;
doc.SaveFile( "./no/such/path/pretty.xml" );
XMLTest( "Issue 302. Fail to save", doc.ErrorName(), "XML_ERROR_FILE_COULD_NOT_BE_OPENED" );
doc.SaveFile( "./resources/out/compact.xml", true );
XMLTest( "Issue 302. Subsequent success in saving", doc.ErrorName(), "XML_SUCCESS" );
-
}
// ----------- Performance tracking --------------