godotengine / godotengine/godot-cpp

Parameter "_p" is null at: Dictionary::_unref

Open
#1,949 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### Godot version

4.6.1

### godot-cpp version

10.0.0-rc1

### System information

Windows 11

### Issue description

I have godot-cpp method that returns a dictionary. I noticed that when it is called I see an error logged.

```
ERROR: Parameter "_p" is null.
at: Dictionary::_unref (core\variant\dictionary.cpp:356)
C# backtrace (most recent call first):
[0] Godot.Collections.Dictionary Godot.NativeCalls.godot_icall_0_122(nint, nint)
omitted the rest
```

When debugging the native code I can see that it is a problem after the godot::Dictionary is returned from my method. The calling code creates a godot-cpp Dictionary and then invokes the assignment operator. This assignment operator calls the godot Engine Dictionary's destructor explicitly, and that calls _unref which has the ref check. Because this is a newly constructed object there is no ref count and ERR_FAIL_NULL catches that.

I see there is a move assignment available for Dictionary. That might be more appropriate in this case. Alternatively, I think the godot-cpp Dictionary class shouldn't call the destructor for the engine Dictionary when it will fail.

### Steps to reproduce

Bind a method that returns a godot::Dictionary and call it. Observe that the error is logged.

### Minimal reproduction project

```
static void _bind_methods() noexcept {
godot::ClassDB::bind_method(godot::D_METHOD("get_dictionary_test"), &MrLinkPlatform::GetDictionaryTest);
}

godot::Dictionary GetDictionaryTest() const noexcept {
godot::Dictionary dict;
dict["key"] = "value";
return dict;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.