From d95b3e97d07a912cbfad9123f80f77935ea61e6a Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 9 Oct 2023 08:30:30 +0100 Subject: [PATCH] fix divide by zero error --- editor/fuzzy_search.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor/fuzzy_search.cpp b/editor/fuzzy_search.cpp index 2448fdbbf080..6ead42a83637 100644 --- a/editor/fuzzy_search.cpp +++ b/editor/fuzzy_search.cpp @@ -35,6 +35,7 @@ #include "scene/gui/tree.h" const int max_results = 100; +const float cull_factor = 0.5f; Vector FuzzySearchResult::get_matches() const { Vector matches_array; @@ -97,6 +98,10 @@ PackedStringArray get_query(const String &p_query) { Vector> sort_and_filter(const Vector> &p_results) { Vector> res; + if (p_results.is_empty()) { + return res; + } + float total_score = 0; for (const Ref &result : p_results) { total_score += result->score; @@ -112,7 +117,7 @@ Vector> sort_and_filter(const Vector i : p_results) { - if (i->score >= mean_score * 0.5) { + if (i->score >= mean_score * cull_factor) { res.push_back(i); }