summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2021-02-18 21:59:09 +0100
committerHugo Locurcio <hugo.locurcio@hugo.pro>2021-02-18 23:01:45 +0100
commit76f1f9b3c56afff2aa144468d8e33f590d6822cd (patch)
tree900b5c51f364d773de4ae3ca71476a2570df5cfa /core
parent247b7e24483931e978f0c203030b5135109655cc (diff)
Don't allow negative values for `OS.delay_usec()`/`OS.delay_msec()`
This closes #46190.
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp12
-rw-r--r--core/core_bind.h4
2 files changed, 12 insertions, 4 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index b446f4c827..2fcaac3688 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -519,11 +519,19 @@ double _OS::get_unix_time() const {
return OS::get_singleton()->get_unix_time();
}
-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);
}
diff --git a/core/core_bind.h b/core/core_bind.h
index 435269dac5..8a4885b82b 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -211,8 +211,8 @@ public:
uint64_t get_static_memory_usage() const;
uint64_t get_static_memory_peak_usage() const;
- void delay_usec(uint32_t p_usec) const;
- void delay_msec(uint32_t p_msec) const;
+ void delay_usec(int p_usec) const;
+ void delay_msec(int p_msec) const;
uint32_t get_ticks_msec() const;
uint64_t get_ticks_usec() const;