From 6baae3e00bbeeca3de2d11a96edb492f6fe32bd4 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Tue, 8 Dec 2020 09:36:01 +0100 Subject: [PATCH] Do not exceed the maximum climate code --- src/Environment/climate.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Environment/climate.cxx b/src/Environment/climate.cxx index 6c84be34e..66b0365b1 100644 --- a/src/Environment/climate.cxx +++ b/src/Environment/climate.cxx @@ -197,8 +197,13 @@ void FGClimate::update(double dt) color = image->getColor(s, t); // convert from color shades to koppen-classicfication - _code = static_cast(floorf(255.0f*color[0]/4.0f)); _gl.elevation_m = 5600.0*color[1]; + _code = static_cast(floorf(255.0f*color[0]/4.0f), 32.0); + if (_code > MAX_CLIMATE_CLASSES) + { + SG_LOG(SG_ENVIRONMENT, SG_WARN, "Climate Koppen code exceeds the maximum"); + _code = MAX_CLIMATE_CLASSES; + } if (_code == 0) set_ocean(); else if (_code < 5) set_tropical();