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

View File

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