Constant.cpp Floating point divide by zero
Constant.cpp will throw a floating point divide by zero if floating point exceptions are enabled in Win32 causing the program to crash. This fix manually checks the right-hand argument of the division and sets appropriate Infinity, Negative Infinity, or NAN as if the floating point exceptions were disabled.
This commit is contained in:
parent
0b964b3c35
commit
e826286f99
1 changed files with 21 additions and 1 deletions
|
|
@ -179,7 +179,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right
|
||||||
case EbtDouble:
|
case EbtDouble:
|
||||||
case EbtFloat:
|
case EbtFloat:
|
||||||
case EbtFloat16:
|
case EbtFloat16:
|
||||||
newConstArray[i].setDConst(leftUnionArray[i].getDConst() / rightUnionArray[i].getDConst());
|
{
|
||||||
|
auto right = rightUnionArray[i].getDConst();
|
||||||
|
auto left = leftUnionArray[i].getDConst();
|
||||||
|
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
newConstArray[i].setDConst(left / right);
|
||||||
|
}
|
||||||
|
else if (left > 0)
|
||||||
|
{
|
||||||
|
newConstArray[i].setDConst((double)INFINITY);
|
||||||
|
}
|
||||||
|
else if (left < 0)
|
||||||
|
{
|
||||||
|
newConstArray[i].setDConst((double)-INFINITY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newConstArray[i].setDConst((double)NAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case EbtInt8:
|
case EbtInt8:
|
||||||
if (rightUnionArray[i] == (signed char)0)
|
if (rightUnionArray[i] == (signed char)0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue