--Bug fixes

-Be more forgiving when loading an Xml with warnings.
This commit is contained in:
mfeemster 2016-03-02 19:16:36 -08:00
parent 7b491c2c24
commit 1c7e95c59a
2 changed files with 124 additions and 125 deletions

View File

@ -431,7 +431,6 @@ public:
return b;
}
/// <summary>
/// Convert an integer to a string.
/// Just a wrapper around _itoa_s() which wraps the result in a std::string.
@ -640,10 +639,9 @@ private:
if (sscanf_s(attStr, "%lu %lu", &currentEmber.m_FinalRasW, &currentEmber.m_FinalRasH) != 2)
{
AddToReport(string(loc) + " : Invalid size attribute " + string(attStr));
xmlFree(attStr);
//These return statements are bad. One because they are inconsistent with others that just assign defaults.
//Two, because assigning easily guessable defaults is easy and less drastic.
return false;
//Assign reasonable defaults.
currentEmber.m_FinalRasW = 1000;
currentEmber.m_FinalRasH = 1000;
}
currentEmber.m_OrigFinalRasW = currentEmber.m_FinalRasW;
@ -654,8 +652,8 @@ private:
if (sscanf_s(attStr, "%lf %lf", &vals[0], &vals[1]) != 2)
{
AddToReport(string(loc) + " : Invalid center attribute " + string(attStr));
xmlFree(attStr);
return false;
vals[0] = 0;
vals[1] = 0;
}
currentEmber.m_CenterX = T(vals[0]);
@ -686,8 +684,9 @@ private:
if (sscanf_s(attStr, "%lf %lf %lf", &vals[0], &vals[1], &vals[2]) != 3)
{
AddToReport(string(loc) + " : Invalid background attribute " + string(attStr));
xmlFree(attStr);
return false;
vals[0] = 0;
vals[1] = 0;
vals[2] = 0;
}
currentEmber.m_Background[0] = T(vals[0]);//[0..1]
@ -1003,8 +1002,8 @@ private:
motion.m_MotionFunc = eMotion::MOTION_SAW;
else
{
AddToReport(string(loc) + " : invalid flame motion function " + func);
return false;
AddToReport(string(loc) + " : invalid flame motion function " + func + ", setting to sin");
motion.m_MotionFunc = eMotion::MOTION_SIN;
}
}
else if (!Compare(curAtt->name, "zoom"))
@ -1038,8 +1037,7 @@ private:
if (sscanf_s(attStr, "%lf %lf %lf", &r, &g, &b) != 3)
{
AddToReport(string(loc) + " : Invalid flame motion background attribute " + string(attStr));
xmlFree(attStr);
return false;
r = g = b = 0;
}
if (r != 0)
@ -1058,8 +1056,7 @@ private:
if (sscanf_s(attStr, "%lf %lf", &cx, &cy) != 2)
{
AddToReport(string(loc) + " : Invalid flame motion center attribute " + string(attStr));
xmlFree(attStr);
return false;
cx = cy = 0;
}
if (cx != 0)
@ -1071,8 +1068,6 @@ private:
else
{
AddToReport(string(loc) + " : Unknown flame motion attribute " + string(CCX(curAtt->name)));
xmlFree(attStr);
return false;
}
xmlFree(attStr);
@ -1089,7 +1084,7 @@ private:
if (soloXform >= 0 && i != soloXform)
currentEmber.GetXform(i)->m_Opacity = 0;//Will calc the cached adjusted viz value later.
return ErrorReport().empty();
return true;
}
/// <summary>

View File

@ -172,6 +172,7 @@ void FractoriumEmberController<T>::OpenAndPrepFiles(const QStringList& filenames
EmberFile<T> emberFile;
XmlToEmber<T> parser;
vector<Ember<T>> embers;
vector<string> errors;
uint previousSize = append ? uint(m_EmberFile.Size()) : 0u;
StopPreviewRender();
emberFile.m_Filename = filenames[0];
@ -196,13 +197,16 @@ void FractoriumEmberController<T>::OpenAndPrepFiles(const QStringList& filenames
m_LastSaveAll = "";
emberFile.m_Embers.insert(emberFile.m_Embers.end(), embers.begin(), embers.end());
errors = parser.ErrorReport();
}
else
{
auto errors = parser.ErrorReport();
m_Fractorium->ErrorReportToQTextEdit(errors, m_Fractorium->ui.InfoFileOpeningTextEdit);
errors = parser.ErrorReport();
m_Fractorium->ShowCritical("Open Failed", "Could not open file, see info tab for details.");
}
if (!errors.empty())
m_Fractorium->ErrorReportToQTextEdit(errors, m_Fractorium->ui.InfoFileOpeningTextEdit);
}
if (append)