Improved 8dd9b8e fix to handle temporary division by 0 cases

This commit is contained in:
Birunthan Mohanathas 2012-04-07 10:06:58 +03:00
parent 16782e56e2
commit 1a5f77254b
2 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@ bool CMeasureCalc::c_RandSeeded = false;
**
*/
CMeasureCalc::CMeasureCalc(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_ValidFormula(false),
m_ParseError(false),
m_LowBound(),
m_HighBound(100),
m_UpdateRandom(false)
@ -58,15 +58,19 @@ bool CMeasureCalc::Update()
{
if (!CMeasure::PreUpdate()) return false;
if (m_ValidFormula)
const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value);
if (errMsg != NULL)
{
const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value);
if (errMsg != NULL)
if (!m_ParseError)
{
LogWithArgs(LOG_ERROR, L"Calc: %s in [%s]", errMsg, m_Name.c_str());
m_ValidFormula = false;
m_ParseError = true;
}
}
else
{
m_ParseError = false;
}
return PostUpdate();
}
@ -106,11 +110,7 @@ void CMeasureCalc::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (errMsg != NULL)
{
LogWithArgs(LOG_ERROR, L"Calc: %s in [%s]", errMsg, m_Name.c_str());
m_ValidFormula = false;
}
else
{
m_ValidFormula = true;
m_Formula.clear();
}
}
}

View File

@ -39,7 +39,7 @@ private:
int GetRandom();
std::wstring m_Formula;
bool m_ValidFormula;
bool m_ParseError;
int m_LowBound;
int m_HighBound;