Skip to content

sort_custom is comparing (unrepeated) element with itself #106599

Open
@MarianoGnu

Description

@MarianoGnu

Tested versions

  • Reproduced in 4.4.1

System information

Windows 11 - Vulkan 1.3.271 - Forward+ - Using Device Nº2: NVIDIA - NVIDIA GeForce RTX 3060 Laptop GPU

Issue description

I have a method that sorts some handlers by priority of execution, but noticed it was printing the warning i added to make sure 2 handlers didn't pick the same priority

func _input_handlers_compare(a: InputHandlerBase, b: InputHandlerBase) -> bool:
	if a.get_priority() == b.get_priority():
		push_warning("input handlers '%s' and '%s' share the same priority %f, will be sort alphabetically by file path" %
		[a.get_script().resource_path, b.get_script().resource_path, a.get_priority()])
		return a.get_script().resource_path > b.get_script().resource_path
	return a.get_priority() > b.get_priority()

after checking, i confirmed the element was not repeated in the array, sort_custom seems to just be comparing the element with itself as part of the algorithm, so i had to add an extra check as a workaround

func _input_handlers_compare(a: InputHandlerBase, b: InputHandlerBase) -> bool:
	if a.get_priority() == b.get_priority():
+		if a == b:
+			# sort_custom is just being dumb, no need to give a warning
+			return false
		push_warning("input handlers '%s' and '%s' share the same priority %f, will be sort alphabetically by file path" %
		[a.get_script().resource_path, b.get_script().resource_path, a.get_priority()])
		return a.get_script().resource_path > b.get_script().resource_path
	return a.get_priority() > b.get_priority()

Steps to reproduce

it's kinda explained in issue description

Minimal reproduction project (MRP)

Not provided (at least until i have time to sit and create one)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions