godotengine / godotengine/godot-cpp
Global godot-type variable cause crash and load gdextension failed
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
4.3.dev(11d3768)
### godot-cpp version
4.3.dev(e23b117)
### System information
win11
### Issue description
This issue have existed for a long time, The reproduction steps are the same as this comment: https://github.com/godotengine/godot-cpp/issues/358#issuecomment-566168170.
```cpp
String s; // crashes
class SomeClass {
static Dictionary d; // crashes
static Node *singleton; // fine, pointer doesn't call a constructor
};
```
This issue is quite tricky, as it is caused by godot **load gdextension .dll** and **initializate GDExtensionInterface**
order.
Do need to solve this problem?
### Steps to reproduce
```
// world.h
const String level0 = "res://level/level0.tscn"; // load gdextension.dll will call String constructor, but this time gdextension function didnt initialized
class World : public Node {
GDCLASS(World, Node)
static void _bind_methods() {}
};
```
Define a global variable `String`, open godot.exe timeline:
1. start open godot.exe
2. godot.exe: Load gdextension.dll -> dll: global variable Construct -> dll: call `String` construct GDExtensionInterface(not initialzed and will Crash)
3. godot.exe: initialize gdextension.dll GDExtensionInterface
### Minimal reproduction project
N/A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.