godotengine / godotengine/godot-cpp
Calling `.ptr()` on empty PackedByteArray returns an error
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### What happens?
Calling the `.ptr()`-method on an empty PackedByteArray returns following error in Godot:
```
E 0:00:01:0376 _ready: Index p_index = 0 is out of bounds (self->size() = 0).
core/extension/gdnative_interface.cpp:691 @ gdnative_packed_byte_array_operator_index_const()
Main.gd:10 @ _ready()
```
### Expected behaviour
Calling the `.ptr()`-method doesn't return an error and returns a nullptr instead.
This is the exact same behaviour as is observed for GDNative's PoolByteArray.
### Environment
Godot-cpp sha: 6c2f9196d76b81de0ea0ff7480767c4c34336882
Godot: Godot 4.0 Beta 5
Platform: Windows 10
### Minimum reproduction code
Code in C++:
```C++
void SQLite::test(PackedByteArray array)
{
UtilityFunctions::print("This is the test method!");
array.ptr();
}
```
Code in GDScript:
```gdscript
extends Control
var db : SQLite = null
func _ready():
db = SQLite.new()
var array := PackedByteArray([1, 2, 3])
db.test(array) # Doesn't return any error
var empty_array := PackedByteArray()
db.test(empty_array) # Returns an error
```
### Additional information
The exact same error is observed for all Packed*Arrays.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.