Skip to content

Commit 2f866ef

Browse files
authored
Merge pull request #1347 from Solesca-Energy/patch
Fix battery segfault from dereferencing std::max_element on an empty array
2 parents 586c88c + 176fe94 commit 2f866ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

shared/lib_battery_dispatch_automatic_fom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void dispatch_automatic_front_of_meter_t::update_dispatch(size_t year, size_t ho
281281
}
282282
}
283283
pv_hours_on = revenueToPVChargeForecast.size() / _steps_per_hour;
284-
revenueToPVChargeMax = pv_hours_on >= t_duration ? *std::max_element(std::begin(revenueToPVChargeForecast), std::end(revenueToPVChargeForecast)): 0;
284+
revenueToPVChargeMax = (!revenueToPVChargeForecast.empty() && pv_hours_on >= t_duration) ? *std::max_element(std::begin(revenueToPVChargeForecast), std::end(revenueToPVChargeForecast)): 0;
285285
}
286286

287287
/*! Economic benefit of charging from clipped PV in current time step to discharge sometime in the next X hours (clipped PV is free) ($/kWh) */

0 commit comments

Comments
 (0)