Skip to content

godot-cpp compiled without a part of all classes existing in Godot can lead to errors and crashes #1163

Closed

Description

@DmitriySalnikov

Godot version

4.1-stable

godot-cpp version

4.1-stable

System information

Windows 10

Issue description

Why am I excluding classes?:

  • Increase the library build speed.
  • Reducing the size of the libraries.

What's wrong?:

As I described in my comment, if I build godot-cpp without part of the classes, for example, ignore building of FontVariation and trying to call this code:

Control *c = memnew(Control);
(Object::cast_to<SceneTree>(Engine::get_singleton()->get_main_loop())->get_root())->add_child(c);
_font = c->get_theme_default_font();
c->queue_free();

get_theme_default_font will output an error even if I don't need to cast the obtained Ref<Font> to Ref<FontVariation>.

Example output:

ERROR: Cannot find instance binding callbacks for class 'FontVariation'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'Timer'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'Panel'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'HBoxContainer'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'MenuBar'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'HBoxContainer'.
   at: (src\core\class_db.cpp:321)
ERROR: Cannot find instance binding callbacks for class 'HBoxContainer'.
   at: (src\core\class_db.cpp:321)
...

Also, for some reason, calling a signal with an argument whose class is not in the library results in nullptr.

For example, a method is called here that connects to the draw signal of the SubViewportContainer class and gets the same
SubViewportContainer as an argument, causes Control *ci to be nullptr.
If I build a library with all classes, then everything is fine. If I apply my patch and ignore most of the classes, then it results in nullptr.

As I understand it, the errors themselves do not affect the functioning of the library, but at the same time nullptr appears in the arguments from somewhere.

Steps to reproduce

cd godot-cpp
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
  • Build it for the editor scons target=editor.
  • Copy/symlink addon from addons folder to an empty project and open it in the editor.
  • The console should be spammed with errors and in the end a crash will occur on the first attempt at drawing here.

Minimal reproduction project

N/A

Activity

  1. dsnopek commented on Jul 7, 2023

    @dsnopek
    Collaborator

    I haven't had a chance to do much testing, but draft PR #1165 should help with the error spam.

    It's possible it could help with the crash too, but I'm not exactly sure what's causing the crash. When we return nullptr, it should fallback on wrapping in Object, which isn't correct, but I wouldn't have expected it to crash.

  2. DmitriySalnikov commented on Jul 7, 2023

    @DmitriySalnikov
    ContributorAuthor

    When we return nullptr, it should fallback on wrapping in Object

    I tried debugging it, and it seemed to me that the main magic is happening, somewhere here

    #ifdef DEBUG_METHODS_ENABLED
    (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
    #else
    (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
    #endif

    Because up to this point and getting inside the _on_canvas_item_draw method, the pointer to the SubViewportContainer was not nullptr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions