Prechádzať zdrojové kódy

Fix RandomPCG::rand_weighted incorrectly returning -1

Togira 1 rok pred
rodič
commit
ab13513403
1 zmenil súbory, kde vykonal 5 pridanie a 0 odobranie
  1. 5 0
      core/math/random_pcg.cpp

+ 5 - 0
core/math/random_pcg.cpp

@@ -60,6 +60,11 @@ int64_t RandomPCG::rand_weighted(const Vector<float> &p_weights) {
 		}
 	}
 
+	for (int64_t i = weights_size - 1; i >= 0; --i) {
+		if (weights[i] > 0) {
+			return i;
+		}
+	}
 	return -1;
 }