Repository: godot
Issue: Crash on exit in GDScriptLanguage after editing some GDScripts
Labels: bug,topic:gdscript,crash

### Godot version

Godot 4.1 e709ad4d6407e52dc62f00a471d13eb6c89f2c4c

### System information

Windows 10 64 bits NVIDIA GeForce GTX 1060

### Issue description

I have a dev build of Godot 4.1 and used it to launch the editor and edit some GDScripts in my project.

After that I closed the project and this happened:
```
Exception has occurred: W32/0xC0000005
Unhandled exception thrown: read access violation.
_Mem was 0xFFFFFFFFFFFFFFFF.

godot.windows.editor.dev.x86_64.exe!std::_Atomic_storage<unsigned int,4>::load(const std::memory_order _Order) Line 1017 (c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic:1017)
godot.windows.editor.dev.x86_64.exe!SafeNumeric<unsigned int>::conditional_increment() Line 139 (godot4_fork\core\templates\safe_refcount.h:139)
godot.windows.editor.dev.x86_64.exe!SafeRefCount::refval() Line 201 (godot4_fork\core\templates\safe_refcount.h:201)
godot.windows.editor.dev.x86_64.exe!RefCounted::reference() Line 59 (godot4_fork\core\object\ref_counted.cpp:59)
godot.windows.editor.dev.x86_64.exe!RefCounted::init_ref() Line 36 (godot4_fork\core\object\ref_counted.cpp:36)
godot.windows.editor.dev.x86_64.exe!Ref<GDScript>::ref_pointer(GDScript * p_ref) Line 76 (godot4_fork\core\object\ref_counted.h:76)
godot.windows.editor.dev.x86_64.exe!Ref<GDScript>::Ref<GDScript>(GDScript * p_reference) Line 186 (godot4_fork\core\object\ref_counted.h:186)
godot.windows.editor.dev.x86_64.exe!GDScriptLanguage::finish() Line 2114 (godot4_fork\modules\gdscript\gdscript.cpp:2114)
godot.windows.editor.dev.x86_64.exe!ScriptServer::finish_languages() Line 229 (godot4_fork\core\object\script_language.cpp:229)
godot.windows.editor.dev.x86_64.exe!Main::cleanup(bool p_force) Line 3575 (godot4_fork\main\main.cpp:3575)
godot.windows.editor.dev.x86_64.exe!widechar_main(int argc, wchar_t * * argv) Line 184 (godot4_fork\platform\windows\godot_windows.cpp:184)
godot.windows.editor.dev.x86_64.exe!_main() Line 204 (godot4_fork\platform\windows\godot_windows.cpp:204)
godot.windows.editor.dev.x86_64.exe!main(int argc, char * * argv) Line 218 (godot4_fork\platform\windows\godot_windows.cpp:218)
godot.windows.editor.dev.x86_64.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 232 (godot4_fork\platform\windows\godot_windows.cpp:232)
godot.windows.editor.dev.x86_64.exe!invoke_main() Line 107 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:107)
godot.windows.editor.dev.x86_64.exe!__scrt_common_main_seh() Line 288 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
godot.windows.editor.dev.x86_64.exe!__scrt_common_main() Line 331 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
godot.windows.editor.dev.x86_64.exe!WinMainCRTStartup(void * __formal) Line 17 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp:17)
kernel32.dll!00007ffdcb657614() (Unknown Source:0)
ntdll.dll!00007ffdcb8c26b1() (Unknown Source:0)
```
![image](https://github.com/godotengine/godot/assets/1311555/9686c4c9-4d8c-4c85-9d1c-5a24a2c14fb2)
![image](https://github.com/godotengine/godot/assets/1311555/243d91ef-7e94-4667-a7bc-8e2ffe72e526)

It seems `GDScriptLanguage::finish()` is trying to access deleted scripts? `script_list` had null members as well.


### Steps to reproduce

I don't know how to reproduce this, it didn't happen in previous sessions. I just opened my project, edited some scripts and then closed the editor.
Maybe if I get more insight later I can update the issue, but crashes on exit are often overlooked since depending on the OS nothing noticeable happens.

Something notable is that in a previous session I had just added `class_name` for the first time to a few scripts in the project, which I used as type hints. It might or might not be relevant.

### Minimal reproduction project

N.A