godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.93k stars 21.15k forks source link

Crash and/or big stutter/freeze when reloading scene with multiple meshes and lights #82576

Open eldidou opened 1 year ago

eldidou commented 1 year ago

Godot version

4.2.dev5

System information

Godot v4.2.dev5 - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Forward+) - integrated Intel(R) UHD Graphics (CML GT2) () - Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz (12 Threads)

Issue description

When reloading a scene that instantiates multiple lights and meshes at startup, the game will freeze for a long time, and in some cases it will also crash.

I works well the first time the scene is loaded during the startup, it's only when reload_current_scene() or change_scene_to_file() is called that the issue is triggered. The (re)loading itself seems fast, but 2~3 frames later there will be a freeze (and possibly a crash).

If shadows are enabled on the lights the freeze is longer and there is no crash. If shadows are disabled there is a crash:

ERROR: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST
   at: swap_buffers (drivers/vulkan/vulkan_context.cpp:2429)
ERROR: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST
   at: swap_buffers (drivers/vulkan/vulkan_context.cpp:2429)
ERROR: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST
   at: swap_buffers (drivers/vulkan/vulkan_context.cpp:2429)

The freeze time grows linearly with the the number of meshes multiplied by the number of lights.

It doesn't happen with all meshes, for some it will have no freeze of crash whatsoever. The minimal project contains two meshes, one that triggers the issue, one that doesn't, they are the same simple mesh, just slightly translated.

It happens only in 4.2, not in 4.1. I've also tried with this commit https://github.com/godotengine/godot/pull/80566, but the issue still happens.

Steps to reproduce

The second loading of the scene (with reload_current_scene) triggers the freeze/crash.

Minimal reproduction project

light_model_instantiate_issue.zip

Rubonnek commented 1 year ago

I'm unable to reproduce with Linux in a build from commit a574c0296b38d5f786f249b12e6251e562c528cc

romgerman commented 7 months ago

Can confirm. I had many duplicated of a model with omni lights (around 100, every model has one omni light) and Godot couldn't change the scene. Instead I was getting VK_ERROR_DEVICE_LOST spam in log. I left some of them (around 8) and it finally worked.

Has happened on 4.2 and 4.3dev5

Rubonnek commented 7 months ago

@romgerman could you provide your system information? I wonder if this issue is related to hardware or if it's due to a driver bug which seems to be the case.

romgerman commented 7 months ago

Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.4626) - AMD Ryzen 5 5600H with Radeon Graphics (12 Threads) NVIDIA Driver 546.26