Skip to content

GDExtension: ScriptInstance binding data becomes invalid or empty after _call is invoked #1881

@JustDooooIt

Description

@JustDooooIt

Godot version

4.5.1

godot-cpp version

4.5.1

System information

windows 11

Issue description

Hello Godot team,

I am developing a JavaScript language binding using GDExtension and godot-cpp, and I've encountered a strange issue where the binding data for a ScriptInstance appears to become corrupted or empty.

Problem Description:

The core issue is with the void* binding data (the instance token) managed by my ScriptLanguageExtension.

On Creation: When my _create_instance function is called, I create a C++ object to represent the script instance and return its pointer as the binding data. At this point, the binding is valid. If I log the object's contents, it prints correctly.

(As you can see in this screenshot, the binding is valid upon creation):
Image
Image

After a _call: Later, when a method is called on this script instance from the engine, my _call function is triggered. The binding data is passed as the p_instance argument. However, when I inspect this p_instance inside _call, it appears to be empty or invalid.

Symptom: The most specific symptom is that when I try to print a representation of the object pointed to by the binding, it only outputs a single newline character.
(This screenshot shows the output when trying to print the binding inside the _call function):
Image
Image

Unexpected Behavior:
What is particularly strange is that the program does not crash. It continues to execute normally, which suggests this might not be a simple null pointer dereference, but perhaps some form of memory corruption or an issue with how the binding data is being managed or passed between the engine and the GDExtension.

Summary of Events:
Inside _create_instance, a valid binding pointer is created and returned. Logging it shows correct data.
A method is called on the script object from Godot.
Inside the corresponding _call function, the received p_instance (the binding) now appears to be invalid, and printing its contents results in only a newline.
Expected Behavior:
The binding pointer (p_instance) passed to _call should be the exact same valid pointer that was returned from _create_instance, pointing to the original, unmodified C++ object.

Actual Behavior:
The binding pointer passed to _call seems to point to invalid or corrupted data. Attempting to access or print the data it points to fails, resulting in an empty line output.

I would appreciate any insights into why the binding data might be getting corrupted between the _create_instance and _call lifecycle hooks. Thank you!

Steps to reproduce

project: https://github.com/GodotHub/gype/tree/2.0
Compile as a dynamic library with MSVC.

Minimal reproduction project

project: https://github.com/GodotHub/gype/tree/2.0

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