Repository: godot
Issue: Crash on loading project (Vulkan memory usage statistics)
Labels: bug,topic:rendering,needs testing,crash

### Godot version

Godot master e69b7083

### System information

Windows 10, Vulkan

### Issue description

Various memory management related crashes on opening a project with a @tool script adding many (441) light sources on a scene. The code crashing may only be a victim, since other memory related crashes can also occur.

Somehow Godot does not like to load scenes with many (400+) lights in them. Something is just unreliable if loading is slow or if it gets processed by a @tool script on load, which I use here to generate such a scene.

Typical traceback on opening the project:
```
Exception: Exception 0xc0000005 encountered at address 0x7ff7742e4213: Access violation reading location 0xffffffffffffffff
---
VmaBlockMetadata_TLSF::Block::IsFree() vk_mem_alloc.h:9998
VmaBlockMetadata_TLSF::AddDetailedStatistics(VmaDetailedStatistics &) vk_mem_alloc.h:10208
VmaBlockVector::AddDetailedStatistics(VmaDetailedStatistics &) vk_mem_alloc.h:12345
VmaAllocator_T::CalculateStatistics(VmaTotalStatistics *) vk_mem_alloc.h:15133
vmaCalculateStatistics(VmaAllocator_T *, VmaTotalStatistics *) vk_mem_alloc.h:16077
RenderingDeviceVulkan::get_memory_usage(MemoryType) rendering_device_vulkan.cpp:9203
RendererRD::Utilities::update_memory_info() utilities.cpp:316
RenderingServerDefault::_draw(bool, double) rendering_server_default.cpp:197
RenderingServerDefault::draw(bool, double) rendering_server_default.cpp:383
Main::iteration() main.cpp:3152
OS_Windows::run() os_windows.cpp:913
widechar_main(int, wchar_t **) godot_windows.cpp:179
_main() godot_windows.cpp:203
main(int, char **) godot_windows.cpp:217
WinMain(HINSTANCE__ *, HINSTANCE__ *, char *, int) godot_windows.cpp:230
[Inlined] invoke_main() 0x00007ff778b6903a
__scrt_common_main_seh() 0x00007ff778b69019
<unknown> 0x00007ff9e7f47034
<unknown> 0x00007ff9e90826a1
```

If the project opens, then clicking on the Output tab crashes in memory management elsewhere:

```
<unknown> 0x00007ff9e912f713
<unknown> 0x00007ff9e91384d2
<unknown> 0x00007ff9e91387ba
<unknown> 0x00007ff9e913e441
<unknown> 0x00007ff9e90560e5
<unknown> 0x00007ff9e9055b74
<unknown> 0x00007ff9e90547b1
_free_base(void *) 0x00007ff778beb540
Memory::free_static(void *, bool) memory.cpp:168
ClusterBuilderRD::_clear() cluster_builder_rd.cpp:231
ClusterBuilderRD::setup(Vector2i, unsigned int, RID, RID, RID) cluster_builder_rd.cpp:249
RenderSceneBuffersRD::configure(RID, Vector2i, Vector2i, float, float, ViewportMSAA, ViewportScreenSpaceAA, bool, bool, unsigned int) render_scene_buffers_rd.cpp:239
RendererViewport::_configure_3d_render_buffers(RendererViewport::Viewport *) renderer_viewport.cpp:182
RendererViewport::_viewport_set_size(RendererViewport::Viewport *, int, int, unsigned int) renderer_viewport.cpp:847
RendererViewport::viewport_set_size(RID, int, int) renderer_viewport.cpp:837
RenderingServerDefault::viewport_set_size(RID, int, int) rendering_server_default.h:583
Viewport::_set_size(const Vector2i &, const Vector2i &, const Rect2i &, const Transform2D &, bool) viewport.cpp:803
SubViewport::set_size(const Vector2i &) viewport.cpp:4079
SubViewportContainer::_notification(int) subviewport_container.cpp:119
SubViewportContainer::_notificationv(int, bool) subviewport_container.h:37
Object::notification(int, bool) object.cpp:790
Control::_size_changed() control.cpp:1651
call_with_variant_args_helper<…>(Control *, void (Control::*)(), const Variant **, Callable::CallError &, IndexSequence<…>) binder_common.h:262
call_with_variant_args<…>(Control *, void (Control::*)(), const Variant **, int, Callable::CallError &) binder_common.h:376
CallableCustomMethodPointer::call(const Variant **, int, Variant &, Callable::CallError &) callable_method_pointer.h:104
Callable::callp(const Variant **, int, Variant &, Callable::CallError &) callable.cpp:50
Object::emit_signalp(const StringName &, const Variant **, int) object.cpp:1045
Object::emit_signal<…>(const StringName &) object.h:873
CanvasItem::item_rect_changed(bool) canvas_item.cpp:451
Control::_size_changed() control.cpp:1654
Control::set_rect(const Rect2 &) control.cpp:1414
Container::fit_child_in_rect(Control *, const Rect2 &) container.cpp:129
Node3DEditorViewportContainer::_notification(int) node_3d_editor_plugin.cpp:5162
Node3DEditorViewportContainer::_notificationv(int, bool) node_3d_editor_plugin.h:484
Object::notification(int, bool) object.cpp:790
Container::_sort_children() container.cpp:94
call_with_variant_args_helper<…>(Container *, void (Container::*)(), const Variant **, Callable::CallError &, IndexSequence<…>) binder_common.h:262
call_with_variant_args<…>(Container *, void (Container::*)(), const Variant **, int, Callable::CallError &) binder_common.h:376
CallableCustomMethodPointer::call(const Variant **, int, Variant &, Callable::CallError &) callable_method_pointer.h:104
Callable::callp(const Variant **, int, Variant &, Callable::CallError &) callable.cpp:50
MessageQueue::_call_function(const Callable &, const Variant *, int, bool) message_queue.cpp:229
MessageQueue::flush() message_queue.cpp:275
SceneTree::physics_process(double) scene_tree.cpp:429
Main::iteration() main.cpp:3111
OS_Windows::run() os_windows.cpp:913
widechar_main(int, wchar_t **) godot_windows.cpp:179
_main() godot_windows.cpp:203
main(int, char **) godot_windows.cpp:217
WinMain(HINSTANCE__ *, HINSTANCE__ *, char *, int) godot_windows.cpp:230
[Inlined] invoke_main() 0x00007ff778b6903a
__scrt_common_main_seh() 0x00007ff778b69019
<unknown> 0x00007ff9e7f47034
<unknown> 0x00007ff9e90826a1
```

Looks like something corrupts memory or a threading/timing issue.

### Steps to reproduce

- Open the MRP
- If Godot would not crash then click on the Output tab at the bottom, so it will

### Minimal reproduction project

[Uploading CrashOnLoadingProject.zip…]()