From ab13513403f085ead06fa1a0ddb2b1e60fe3fe02 Mon Sep 17 00:00:00 2001 From: Togira <70365614+Togira123@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:58:24 +0200 Subject: [PATCH] Fix RandomPCG::rand_weighted incorrectly returning -1 --- core/math/random_pcg.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 55787a0b57e..c286a604218 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -60,6 +60,11 @@ int64_t RandomPCG::rand_weighted(const Vector &p_weights) { } } + for (int64_t i = weights_size - 1; i >= 0; --i) { + if (weights[i] > 0) { + return i; + } + } return -1; }