Skip to content

Variant assignment can lead to null value #1959

Closed

Description

@Naros

Godot version

4.7 and 4.6

godot-cpp version

10, as well as 4.6

System information

Fedora 42

Issue description

When performing a Variant assignment where both refer to the same underlying memory, the variable will become <null> because the underlying godot-cpp Variant::operator= method blindly calls clear().

However, if we compare this to the engine's Variant::operator= method:

if (unlikely(this == &p_variant)) {
  return;
}

The engine guards against corner cases, so that the memory is not corrupted.

Steps to reproduce

Variant v1 = 1;
Variant* v2 = &v1;
*v2 = v1;
UtilityFunctions::prints(*v2, v1);

The output of the print is <null> <null>.

When building code, such as scripting languages where you are working with arrays of variants for stack parameters, it's very likely to hit this use case where a user may write i = i in their code, where i variable refers to some random Variant allocated on the function/script execution stack.

Minimal reproduction project

n/a

Activity

  1. added
    bug
    on Mar 30, 2026
  2. added a commit that references this issue on Mar 30, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions