Don't allow negative values for OS.delay_usec()/OS.delay_msec()

This closes #46190.

(cherry picked from commit 76f1f9b3c5)
This commit is contained in:
Hugo Locurcio
2021-02-18 21:59:09 +01:00
committed by Rémi Verschelde
parent 2fb221e79a
commit 9f236d48e6
3 changed files with 14 additions and 8 deletions

View File

@@ -942,13 +942,19 @@ uint64_t _OS::get_system_time_msecs() const {
return OS::get_singleton()->get_system_time_msecs();
}
void _OS::delay_usec(uint32_t p_usec) const {
/** This method uses a signed argument for better error reporting as it's used from the scripting API. */
void _OS::delay_usec(int p_usec) const {
ERR_FAIL_COND_MSG(
p_usec < 0,
vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
OS::get_singleton()->delay_usec(p_usec);
}
void _OS::delay_msec(uint32_t p_msec) const {
/** This method uses a signed argument for better error reporting as it's used from the scripting API. */
void _OS::delay_msec(int p_msec) const {
ERR_FAIL_COND_MSG(
p_msec < 0,
vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
}