diff options
author | George Marques <george@gmarqu.es> | 2023-10-18 14:12:51 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2023-10-18 14:12:51 -0300 |
commit | 08e3f30299acfbfcbfb074a2fd762a63f7d0850b (patch) | |
tree | 40324f3dbdd133d06d0a976231d845e9d4583b51 | |
parent | 7f884b4e0017368e193d96f425aac6c2d8a86eb0 (diff) | |
download | redot-engine-08e3f30299acfbfcbfb074a2fd762a63f7d0850b.tar.gz |
GDScript: Don't optimize division and modulo on debug
Since the validated operators don't have checks for division by zero,
use the regular evaluator in debug which has those checks.
-rw-r--r-- | modules/gdscript/gdscript_vm.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index b723ecc185..d31411b26b 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -662,6 +662,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a uint32_t op_signature = _code_ptr[ip + 5]; uint32_t actual_signature = (a->get_type() << 8) | (b->get_type()); +#ifdef DEBUG_ENABLED + if (op == Variant::OP_DIVIDE || op == Variant::OP_MODULE) { + // Don't optimize division and modulo since there's not check for division by zero with validated calls. + op_signature = 0xFFFF; + _code_ptr[ip + 5] = op_signature; + } +#endif + // Check if this is the first run. If so, store the current signature for the optimized path. if (unlikely(op_signature == 0)) { static Mutex initializer_mutex; |