-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print suggestions when requesting a nonexistent InputMap action #35666
Print suggestions when requesting a nonexistent InputMap action #35666
Conversation
e6372ff
to
d090074
Compare
Where the comparator resides doesn't cause any performance issues. It would be the fact that the similarity between strings would be computed multiple times during sorting (since it's done on the fly). Computing it once for each and sorting in a second pass would be faster, if you think there can be a lot of elements to sort. Maybe something like: struct Pair {
StringName action;
int similarity; // dunno if it's float or int?
};
// Convert the List to a Vector to use a custom sorting function.
for (int i = 0; i < actions.size(); i++) {
actions_vector.write[i] = { actions[i], (String(actions[i])).similarity(base_name) };
}
// Sort the vector's elements from the most to least similar.
struct Comparator {
inline bool operator()(const Pair &a, const Pair &b) const {
return a.similarity < b.similarity;
}
};
SortArray<Pair, Comparator> sorter;
sorter.compare.base_name = p_action;
sorter.sort(actions_vector.ptrw(), actions_vector.size());
Wow, debug is slow but that's still a lot... that's just the sorting part? How many elements is it sorting? |
It might be worth to somehow generalize this function, so that it can be used for missing variables / methods / etc. |
d090074
to
5066461
Compare
@Zylann It turns out I don't need to do any sorting, as I only need the most similar item. The new method is about 10 times faster on average 🙂 |
@Calinou and if you want it even faster, iterate the list using |
5066461
to
74ab20a
Compare
@Zylann Thanks for the suggestion, it's even faster now (100-150 µs). |
@Calinou Is there any update on this? This looks like it would be a great help for beginners and anyone prone to typos. |
Needs a rebase, otherwise should be fine to merge. To be fair I'm not convinced that adding such contextual info to runtime errors is really a good UX, but I guess it's better than nothing. |
What if this was inside of |
I remember someone asking on reddit why their Edit: see: |
That shouldn't be necessary, the error macros already ignore the message if |
Yeah, it's just that from those two threads it doesn't appear like those users even looked at the errors in the debugger/console, so whether the error says To me, it's clear enough if you're told that a given action name doesn't exist, that you might indeed be using an action that doesn't exist - so you check the InputMap and your code to make sure it's correct. If those two users failed to do that, they likely did not even see the error, which is a different UX problem. All that being said, I'm fine with the change if it can help some users at least. |
I think this is the kind of error that should pause project execution and raise the editor window, similar to GDScript errors. ( |
74ab20a
to
7cc20e0
Compare
Rebased. PS: I noticed that no error message is printed at all when using |
7cc20e0
to
07f5f26
Compare
Co-authored-by: Marc Gilleron <marc.gilleron@gmail.com>
07f5f26
to
71b254f
Compare
Rebased and tested on the latest Since the |
Thanks! |
This should make debugging input actions a bit easier. In the future, we can extend this to
get_node()
errors, signal connection errors and much more. If no action name is close enough to the requested action, no suggestion will be made.3.2
version of this PR: #45902Preview
Note that this method is fairly slow (taking 2-5 ms to run in a debug build). Thankfully, it's only called in debug builds when the input action doesn't exist, so the impact should be minimal in a release build.@Zylann Is there a way to optimize this? I'm not sure if putting the Comparator struct outside the function would improve the performance (to avoid creating it every time).Edit: The method has been optimized, it takes about 100-150 µs to run now.