mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 11:54:04 +02:00
Fix crash when doing sim.ambientAirTemp(0/0)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -43,9 +44,12 @@ inline unsigned clamp_flt(float f, float min, float max)
|
|||||||
|
|
||||||
inline float restrict_flt(float f, float min, float max)
|
inline float restrict_flt(float f, float min, float max)
|
||||||
{
|
{
|
||||||
if (f<min)
|
// Fix crash in certain cases when f is nan
|
||||||
|
if (!std::isfinite(f))
|
||||||
return min;
|
return min;
|
||||||
if (f>max)
|
if (f < min)
|
||||||
|
return min;
|
||||||
|
if (f > max)
|
||||||
return max;
|
return max;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user