Class inheritance method override does not work in 4.8 beta 1

已关闭
#2,083 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp, godot
领域
backend

调研方向

Start with the reproduction in addons/test/cTest.h and main.gd, then compile it with addons/test/compite_debug.sh using Godot 4.8 beta and the listed godot-cpp commits. Compare the inherited test method behavior with versions before 4.8; done when b.test(im) accepts the Image argument while a.test(ba) still works.

由索引模型根据 Issue 内容生成。

描述

bug
Godot version

4.8.beta1

godot-cpp version

1b089f20a959e67e79e32e352a57065b3058dbfd

System information

Ubuntu 24.04

Issue description

We have two classes, see reproduction project (addons/test/cTest.h):

class cTestA : public RefCounted {
	GDCLASS(cTestA, RefCounted)

    public: 
        cTestA(){}
        ~cTestA(){}
        void test(PackedByteArray byte_array){
            UtilityFunctions::print("cTestA: test function call: PackedByteArray");
        }
    protected:
        static void _bind_methods(){
            ClassDB::bind_method(D_METHOD("test", "byte_array"), &cTestA::test);
        };
};

class cTestB : public cTestA {
	GDCLASS(cTestB, cTestA)
   
    public:
        cTestB(){}
        ~cTestB(){}
        void test(Ref<Image> image){
            UtilityFunctions::print("cTestB: test function call: Ref<Image>");
        }
    protected:
        static void _bind_methods(){
            ClassDB::bind_method(D_METHOD("test", "image2d"), &cTestB::test);
        };
};

But in GDScript (main.gd):

func _ready() -> void:
	var a := cTestA.new()
	var b := cTestB.new()
	var ba := PackedByteArray([0,0,0])
	var im := Image.create_empty(128, 128, false, Image.FORMAT_RF)
	a.test(ba)
	b.test(im)

I get an error: "Error at (8, 12): Invalid argument for "test()" function: argument 1 should be "PackedByteArray" but is "Image"."
This problem did not exist in any version <4.8.
Tested with:

  1. godot-cpp commit 1b089f20a959e67e79e32e352a57065b3058dbfd
  2. godot-cpp commit 507ed9d840c01a3c5b2a39af8bb4000bfac30bf5
Steps to reproduce

See reproduction project. Compile script: addons/test/compite_debug.sh
To compile:

cd addons/test
git clone [email protected]:godotengine/godot-cpp.git
chmod +x compite_debug.sh
./compite_debug.sh

then open this project in Godot 4.8 beta.

Minimal reproduction project

InheritanceTest.zip

主要语言
C++
星标
2.8k
派生
829
平均合并
3 天 12 小时
30 天内合并 PR
16

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

godotengine/godot-cpp 的其他 Issue

查看 godotengine/godot-cpp 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。