Control virtual methods are not dispatched properly in a multi-tiered custom class hierarchy
Godot version
4.2.0-stable
godot-cpp version
4.2.0-stable
System information
Windows 11, MSVC 2022
Issue description
When creating a custom implementation of GraphNode and adding custom logic inside _has_point and _get_tooltip, the behavior of these methods differs between DEBUG and RELEASE builds.
On debug builds, these methods are called whereas for RELEASE builds they are not.
It's important to note that the class hierarchy is GraphNode --> MyGraphNode --> MyGraphNodeComment. These virtual methods are implemented on the comment node only.
A workaround appears to be that to have consistent behavior across builds, the overridden methods must also be overridden in the MyGraphNode class with default implementations, i.e.:
bool _has_point(const Vector2& p_point) const override { return GraphNode::_has_point(p_point); }
String _get_tooltip(const Vector2& p_point) const override { return GraphNode::_get_tooltip(p_point); }
Steps to reproduce
- Create a custom class
MyGraphNodethat is derived fromGraphNode. - Create another custom class
MyGraphNodeCommentthat derives fromMyGraphNode. - Implement
_has_pointand_get_tooltipwith custom behavior insideMyGraphNodeComment, i.e.
bool MyGraphNodeComment::_has_point(const Vector2& p_point) const
{
Ref<Texture2D> resizer = get_theme_icon("resizer");
if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point))
return true;
if (Rect2(Point2(), Vector2(get_size().x, 28)).has_point(p_point))
return true;
return false;
}
String MyGraphNodeComment::_get_tooltip(const godot::Vector2& p_point) const
{
if (Rect2(Point2(), Vector2(get_size().x, 28)).has_point(p_point))
return get_tooltip_text();
return "";
}
- Under debug builds, these methods are fired just fine but aren't fired under release builds.
Editor - 4.2 stable official
Godot CPP - Checkout hash 4.2.0-stable 0f78fc45bd9208793736afda6c56ff7e85d4d285
Minimal reproduction project
N/A
Thanks!
When you talk about debug vs release builds, are you referring to debug/release builds of Godot or debug/release builds of your GDExtension? Or, always paired (debug Godot build with debug GDExtension build, and vice versa for release)?
Unfortunately, I've been unable to reproduce this so far. I tried adding a test case which makes a sub-sub-class with _get_tooltip() which is in this patch.
I tried running the tests with Godot 4.2.1-stable with the editor (debug) running a debug build of the test GDExtension, the editor (debug) with a release build of the test GDExtension, and exporting the project (so, release template of Godot 4.2.1-stable) with a release build of the test GDExtension -- the tests passed in every combination.
Can you provide an MRP or more instructions on how to reproduce? Thanks!