Skip to content
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

fix: 🐛 Transitive Comparator for script sorting #277

Merged
merged 4 commits into from
Jun 17, 2023

Conversation

boardengineer
Copy link
Contributor

The current algorithm returns a random result unless a is in b's type hierarchy. Random results are disallowed in the sort_custom API

https://docs.godotengine.org/en/3.5/classes/class_array.html?highlight=sort_custom

The new algorithm sorts alphabetically by names in the type hierarchy paths until one of the trees stop then it sorts the shorter tree first.

Aims to fix the following errors that gets spammed at startup (and i think causes startup crashes):

E 0:00:00.815 SortArray<class Variant,struct _ArrayVariantSortCustom,1>::partitioner: bad comparison function; sorting will be broken
<C++ Source> .\core/sort_array.h:179 @ SortArray<class Variant,struct _ArrayVariantSortCustom,1>::partitioner()
script_extension.gd:39 @ handle_script_extensions()
mod_loader.gd:164 @ _load_mods()
mod_loader.gd:67 @ _init()

The current algorithm returns a random result unless a is in b's type hierarchy.  Random results are disallowed in the sort_custom API

https://docs.godotengine.org/en/3.5/classes/class_array.html?highlight=sort_custom

The new algorithm sorts alphabetically by names in the type hierarchy paths until one of the trees stop then it sorts the shorter tree first.

Aims to fix the following errors that gets spammed at startup (and i think causes startup crashes):

E 0:00:00.815   SortArray<class Variant,struct _ArrayVariantSortCustom,1>::partitioner: bad comparison function; sorting will be broken
  <C++ Source>  .\core/sort_array.h:179 @ SortArray<class Variant,struct _ArrayVariantSortCustom,1>::partitioner()
  <Stack Trace> script_extension.gd:39 @ handle_script_extensions()
                mod_loader.gd:164 @ _load_mods()
                mod_loader.gd:67 @ _init()
@KANAjetzt KANAjetzt added the bug Something isn't working label Jun 16, 2023
@KANAjetzt KANAjetzt added this to the v6.0.0 milestone Jun 16, 2023
@KANAjetzt KANAjetzt changed the title Transitive Comparator for script sorting fix: Transitive Comparator for script sorting Jun 16, 2023
@KANAjetzt KANAjetzt mentioned this pull request Jun 16, 2023
15 tasks
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for the contribution 😃

Comparing the stacks looks wrong at first glance since it just compares the scripts at the same index in the stack, but with push_front it starts to make sense. Both stacks start after the native Godot classes and work up from there. No matter where both stacks would go apart, they will always arrive at the same vanilla script at the same time.
On that note - I assume get_base_script does not return Godot classes, right? Otherwise it could cause issues

Another thing: The code does not use ModLoaderStore.loaded_vanilla_parents_cache.keys() anymore. I think this was the only place where it was used, so it can be removed from the store and also where it is updated. Please have a look

addons/mod_loader/internal/script_extension.gd Outdated Show resolved Hide resolved
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thank you.

Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocked until the bug we discussed on discord is fixed

@Qubus0 Qubus0 self-requested a review June 17, 2023 20:01
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important fix, thank you 👍

@Qubus0 Qubus0 added this pull request to the merge queue Jun 17, 2023
Merged via the queue into GodotModding:development with commit 286f296 Jun 17, 2023
@ithinkandicode ithinkandicode changed the title fix: Transitive Comparator for script sorting fix: 🐛 Transitive Comparator for script sorting Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants