Repository: godot
Issue: C++ GDExtension crash only on Godot release version, but not in debug_release or debug versions of Godot.
Labels: bug,topic:gdextension,crash,topic:export

### Godot version

4.0 alpha 14 custom build (carefully stripped version of official version), 4.0 alpha 14 official

### System information

Windows 10, i5-9300H, NVIDIA GeForce GTX 1650 Mobile

### Issue description

First, I am a C++ newbie and I didn't found duplicates from those issues.
and I tried to make this as readable as I can.
this compiled C++ file "cosmic.windows.release.x86_64.dll" crashes Godot for some reason.
![running the export build and crash](https://user-images.githubusercontent.com/99343051/186737213-d4965270-cea3-416d-955d-baae3001998e.png)
but the debug version "cosmic.windows.debug.x86_64.dll" won't. (won't crash)
![debug n export build](https://user-images.githubusercontent.com/99343051/186737334-2f98d116-dde4-48f4-b1ad-ccea44d44549.png)
I don't know why this won't work? it's literally the same C++ file.
Editor running fine:
![okay in editor](https://user-images.githubusercontent.com/99343051/186737559-850754fb-2d74-4b4b-9813-3ef1e5990847.png)


The C++ code:
![The C++ code](https://user-images.githubusercontent.com/99343051/186772101-9367ec40-6b98-478e-92e3-aceeed3b6d6d.png)

GDScript code:
![GDScript code](https://user-images.githubusercontent.com/99343051/186772487-3193b7bb-80f5-4e9c-b3c4-c4a7fd037c52.png)

Yeah, it's crashing on these short codes.
and I will open two new issues about "calling the C++ to get different results
with the GDExtension and the same code every time you start the game"
later if this is a valid issue and not my(user) error.
and "export version of Godot will not found .GDExtension and .dll the files if
it's in .zip or .pck file"

# Quick peak
## cosmic.cpp:
![cosmic](https://user-images.githubusercontent.com/99343051/186772725-6d586ae7-8f6d-4dcc-9197-e1cc85779fff.png)

## cosmic.h:
![cosmic_h](https://user-images.githubusercontent.com/99343051/186772878-8a2a2370-a468-4a8c-89f1-3ae25cc10b47.png)

## register_types.cpp:
![register_types](https://user-images.githubusercontent.com/99343051/186772848-5cc78e2a-3926-4023-afad-871f7a78e3a3.png)

## register_types.h:
![register_types_h](https://user-images.githubusercontent.com/99343051/186772932-9f5c553b-29b4-4acd-9e44-8edf76c2c37e.png)

### Steps to reproduce

# Short version (Exported file only)
Download the "my game export.zip"
[my game export_2.zip](https://github.com/godotengine/godot/files/9428488/my.game.export_2.zip)
Download this and extract "windows_debug_x86_64.exe" and
put "windows_release_x86_64.exe" with the zip(a.zip) file.
https://downloads.tuxfamily.org/godotengine/4.0/alpha14/Godot_v4.0-alpha14_export_templates.tpz
(or in the extracted game export.zip)
("a.zip" is game resource file)
And then run both of them with this:
```
windows_debug_x86_64.exe --main-pack a.zip & ^
windows_release_x86_64.exe --main-pack a.zip
```
Only the debug version will not crash.
The release version crash for no warning or reason.

# Short version 2 (Compiling the cpp file with prepared template)
Download the "prepared template.zip".
[prepared template_2.zip](https://github.com/godotengine/godot/files/9428489/prepared.template_2.zip)
Then compile at the root folder with the:
```
cd godot-cpp && scons target=debug && cd .. && ^
scons target=debug && scons target=release
```
And then you export the game with .pck or .zip and test it.

# Long version (Compiling the cpp file from scratch)
## Download
Get the "game project.zip" template from here.
[game project_2.zip](https://github.com/godotengine/godot/files/9428481/game.project_2.zip)
Get the GDExtensionSummator template from
https://github.com/paddy-exe/GDExtensionSummator
(it's commit 7e5a351.)
Get the godot-cpp @ 8498f64
https://github.com/godotengine/godot-cpp/tree/8498f64a506ba96bce82f1506567be16938b831c

## Extracting
Extract the GDExtensionSummator template.
Extract the godot-cpp(without the root folder)
and move it in "GDExtensionSummator\godot-cpp".

## Replacing
Delete the "extension" and "game" folder and the file "SConstruct"
(it's "\extension\src" and "\game" and \SConstruct.)
Extract the "game project.zip" from root of the template folder.
(which include "extension", "game" folder and the file "SConstruct")

## Compiling
**"Compile the godot-cpp first"** in cmd with ```scons``` (it default to debug version.)
And compile the GDExtensionSummator template with debug and release version.
```scons && scons target=release```

Or compiling in one line in cmd:
```
cd godot-cpp && scons target=debug && cd .. && ^
scons target=debug && scons target=release
```
This mostly breaks for you... I don't recommend it.


### Minimal reproduction project

[GDExtensionSummator-main.zip](https://github.com/godotengine/godot/files/9427093/GDExtensionSummator-main.zip)
[godot-cpp-8498f64a506ba96bce82f1506567be16938b831c.zip](https://github.com/godotengine/godot/files/9427110/godot-cpp-8498f64a506ba96bce82f1506567be16938b831c.zip)
[my game export.zip](https://github.com/godotengine/godot/files/9427113/my.game.export.zip)
[game project.zip](https://github.com/godotengine/godot/files/9427114/game.project.zip)
[prepared template.zip](https://github.com/godotengine/godot/files/9427115/prepared.template.zip)
New files:
[my game export_2.zip](https://github.com/godotengine/godot/files/9428488/my.game.export_2.zip)
[game project_2.zip](https://github.com/godotengine/godot/files/9428481/game.project_2.zip)
[prepared template_2.zip](https://github.com/godotengine/godot/files/9428489/prepared.template_2.zip)