godotengine / godotengine/godot-cpp
Control virtual methods are not dispatched properly in a multi-tiered custom class hierarchy
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### 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.:
```cpp
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
1. Create a custom class `MyGraphNode` that is derived from `GraphNode`.
2. Create another custom class `MyGraphNodeComment` that derives from `MyGraphNode`.
3. Implement `_has_point` and `_get_tooltip` with custom behavior inside `MyGraphNodeComment`, i.e.
```cpp
bool MyGraphNodeComment::_has_point(const Vector2& p_point) const
{
Ref 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 "";
}
```
4. 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.