X Tutup
Skip to content

Add GDSOFTCLASS to deeper inheritors of Object#110837

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
wheatear-dev:add-gdsoftclass-deeper
Sep 25, 2025
Merged

Add GDSOFTCLASS to deeper inheritors of Object#110837
Repiteo merged 1 commit intogodotengine:masterfrom
wheatear-dev:add-gdsoftclass-deeper

Conversation

@wheatear-dev
Copy link
Contributor

@wheatear-dev wheatear-dev commented Sep 23, 2025

Hi all 👋 (cc. @Ivorforce )

Further to bug report #110693, which was prematurely closed, and in which it was discovered that static casting errors occur when:

  1. inheriting from Object - directly or otherwise
  2. but not defining an appropriate GDCLASS or GDSOFTCLASS at each child class

And notwithstanding that my previous PR's (#110694 and #110752) fixed part of the problem, by fixing direct children of Object. Please note that this is not - however - sufficient, since there can be children deeper in the inheritance tree that will still exhibit this bug.

This PR seeks to locate all those remaining - deeper in the inheritance tree from Object - and fix them by adding an appropriate GDSOFTCLASS.

Changes

  • GDSOFTCLASS added to many classes
  • override keywords added to public methods in:
    • editor/export/gdextension_export_plugin.h
    • modules/multiplayer/multiplayer_debugger.h
    • platform/android/net_socket_android.h

How to validate

  1. install ripgrep
  2. Use (check first!) this script
#!/bin/bash

# List of parent classes (derived from the PR)
classes=(
    Object
	ResourceFormatLoader
	ResourceFormatSaver
	EngineProfiler
	RefCounted
	RemoteDebuggerPeer
	HTTPClient
	NetSocket
	EditorDebuggerServer
	CodeSignBlob
	EditorExportPlugin
	ShaderBakerExportPluginPlatform
	NetSocketUnix
	PhysicsServer2D
	PhysicsServer3D
	RenderingDeviceCommons
	RenderingServer
    NavMeshGenerator2D
    NavMeshGenerator3D
    BetsyCompressor
)

for cls in "${classes[@]}"; do
	echo "Searching for classes derived from $cls..."
	rg --pcre2 -n -H -o --multiline --multiline-dotall \
	  "^(class\s+(\w+)\s*:\s*public\s+$cls\s*\{(?:(?!GDCLASS|GDSOFTCLASS).)*?\})" \
	  --glob '*.h' --glob '*.cpp' \
	  --glob '!*.gen.h' --glob '!test*.h' \
	  --glob '!thirdparty/**' \
	  --replace '$2'
done

Thanks! 😄

Methodology

They were initially found with this script and output, and then manually refined and expanded. Please note that:

  • the script has problems with duplicates (similarly named classes in different files), and can't distinguish them, due to not actually interpreting C++ source code.
  • some classes were manually marked with SKIP in the output, since they were either a duplicate - of a similarly named class that does descend from Object - or a descendant of such a duplicate.

@wheatear-dev wheatear-dev requested review from a team as code owners September 23, 2025 19:31
@wheatear-dev wheatear-dev requested a review from a team September 23, 2025 19:31
@wheatear-dev wheatear-dev requested review from a team as code owners September 23, 2025 19:31
@wheatear-dev wheatear-dev changed the title Add GDSOFTCLASS to deeper inheritors of Object Add GDSOFTCLASS to deeper inheritors of Object Sep 23, 2025
@wheatear-dev wheatear-dev force-pushed the add-gdsoftclass-deeper branch 2 times, most recently from 77f29aa to 5e682f4 Compare September 23, 2025 19:46
@wheatear-dev wheatear-dev requested review from a team as code owners September 23, 2025 19:46
@wheatear-dev wheatear-dev requested review from a team as code owners September 23, 2025 20:05
@wheatear-dev wheatear-dev force-pushed the add-gdsoftclass-deeper branch 5 times, most recently from 669b994 to b5ea7b6 Compare September 23, 2025 20:47
@Calinou Calinou added this to the 4.6 milestone Sep 23, 2025
Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

While this is quite a bit of churn for no immediate benefit, I think this is a necessary change:

  • Without GDSOFTCLASS, future contributors or module authors might run into the same issue as #110693.
  • We should have consistency in the codebase about what it means to derive from Object.
  • We may decide to add more semantics to GDSOFTCLASS, which may make it necessary for these classes to use the macro.

I actually may propose to require the use of GDSOFTCLASS / GDCLASS, but for now, this is an appropriate improvement.

Thank you again @wheatear-dev for going through the trouble of identifying and patching these!

@Ivorforce Ivorforce requested review from a team and removed request for a team September 24, 2025 19:44
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

This should be a totally safe change

@Repiteo Repiteo merged commit c32c260 into godotengine:master Sep 25, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 25, 2025

Thanks!

@wheatear-dev wheatear-dev deleted the add-gdsoftclass-deeper branch September 25, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup