godotengine / godot

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

Viewport "Render Direct To Scene" crashes the editor #58499

Open dzil123 opened 2 years ago

dzil123 commented 2 years ago

Godot version

v3.4.2.stable.official.45eaa2daf

System information

Arch Linux (x86_64 latest), GLES2

Issue description

Given a project on GLES2, a Viewport node with Fxaa enabled, a Spatial node and a Camera as a child of the Viewport node: enabling the Viewport node's render_direct_to_screen property will crash the editor.

This occurs on multiple computers with different GPUs, so I don't think the GPU model and driver version are relevant.

Godot Engine v3.4.2.stable.official.45eaa2daf - https://godotengine.org
OpenGL ES 2.0 Renderer: AMD Radeon RX 580 Series (POLARIS10, DRM 3.42.0, 5.15.24-2-lts, LLVM 13.0.1)
OpenGL ES Batching: ON

ERROR: FATAL: Index p_index = 0 is out of bounds (size() = 0).
   at: get (./core/cowdata.h:156)

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v3.4.2.stable.official (45eaa2daf1e3d2571a9f31a3421911262ec82f51)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /usr/lib/libc.so.6(+0x42560) [0x7f01414d5560] (??:0)
[2] ./Godot_v3.4.2-stable_x11.64() [0x13444b2] (??:0)
[3] ./Godot_v3.4.2-stable_x11.64() [0x27e0536] (??:0)
[4] ./Godot_v3.4.2-stable_x11.64() [0x2e92a75] (??:0)
[5] ./Godot_v3.4.2-stable_x11.64() [0x27d3a69] (??:0)
[6] ./Godot_v3.4.2-stable_x11.64() [0x27f25c0] (??:0)
[7] ./Godot_v3.4.2-stable_x11.64() [0x9d8ef3] (??:0)
[8] ./Godot_v3.4.2-stable_x11.64() [0x94655d] (??:0)
[9] /usr/lib/libc.so.6(+0x2d310) [0x7f01414c0310] (??:0)
[10] /usr/lib/libc.so.6(__libc_start_main+0x81) [0x7f01414c03c1] (??:0)
[11] ./Godot_v3.4.2-stable_x11.64() [0x95a18e] (??:0)
-- END OF BACKTRACE --
================================================================
Aborted (core dumped)

Steps to reproduce

  1. Open the minimal reproduction project.
  2. Select the Viewport node.
  3. Enable the "Render Direct To Screen" property in the Inspector.
  4. Crash.

Minimal reproduction project

SampleProject.zip

qarmin commented 2 years ago
ERROR: FATAL: Index p_index = 0 is out of bounds (size() = 0).
   at: get (./core/cowdata.h:156)

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v3.5.beta.custom_build (e2287a201a54a113bb1461cd5997a23cc9c1f50d)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] godots() [0x1851e4a] (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/crash_handler_x11.cpp:55)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x46520) [0x7f77d0b62520] (??:0)
[3] CowData<RasterizerStorageGLES2::RenderTarget::MipMaps::Size>::get(int) const (/home/runner/work/GodotBuilds/GodotBuilds/godot/./core/cowdata.h:156 (discriminator 7))
[4] Vector<RasterizerStorageGLES2::RenderTarget::MipMaps::Size>::operator[](int) const (/home/runner/work/GodotBuilds/GodotBuilds/godot/./core/vector.h:87)
[5] RasterizerSceneGLES2::_post_process(RasterizerSceneGLES2::Environment*, CameraMatrix const&) (/home/runner/work/GodotBuilds/GodotBuilds/godot/drivers/gles2/rasterizer_scene_gles2.cpp:2831)
[6] RasterizerSceneGLES2::render_scene(Transform const&, CameraMatrix const&, int, bool, RasterizerScene::InstanceBase**, int, RID*, int, RID*, int, RID, RID, RID, RID, int) (/home/runner/work/GodotBuilds/GodotBuilds/godot/drivers/gles2/rasterizer_scene_gles2.cpp:3628)
[7] VisualServerScene::_render_scene(Transform, CameraMatrix const&, int, bool, RID, RID, RID, RID, int) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_scene.cpp:3233)
[8] VisualServerScene::render_camera(RID, RID, Vector2, RID) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_scene.cpp:2810 (discriminator 2))
[9] VisualServerViewport::_draw_3d(VisualServerViewport::Viewport*, ARVRInterface::Eyes) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:68)
[10] VisualServerViewport::_draw_viewport(VisualServerViewport::Viewport*, ARVRInterface::Eyes) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:109)
[11] VisualServerViewport::draw_viewports() (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:351)
[12] VisualServerRaster::draw(bool, double) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_raster.cpp:117 (discriminator 4))
[13] VisualServerWrapMT::draw(bool, double) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_wrap_mt.cpp:122)
[14] Main::iteration() (/home/runner/work/GodotBuilds/GodotBuilds/godot/main/main.cpp:2290)
[15] OS_X11::run() (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/os_x11.cpp:3722)
[16] godots(main+0x329) [0x18480ef] (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/godot_x11.cpp:57)
[17] /lib/x86_64-linux-gnu/libc.so.6(+0x2dfd0) [0x7f77d0b49fd0] (??:0)
[18] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7d) [0x7f77d0b4a07d] (??:0)
[19] godots(_start+0x2e) [0x1847d0e] (??:?)
-- END OF BACKTRACE --
================================================================
vzuzik commented 1 year ago

crash happens because code trying to copy color buffer from destroyed mipmap level to gles2::system_fbo color buffer (gles2::system_fbo sets when Render Direct To Screen mode activated as current_rt->color)

file: rasterizer_scene_gles2.cpp

  1. use_post_process become true value in this place image

  2. then makes a copy to system_fbo from non existing mipmap level of current_rt in this place (line 2849) image

this happens because in _render_target_allocate code sets the mip_maps_allocated to true, but when mode Render Direct To Screen sets, this flag no reset in _render_target_allocate because function exits early in if condition (on screenshot), but all mipmaps clears and fbo destroyed in _render_target_clear image

vzuzik commented 1 year ago

some update. Crash can be fixed by moving that lines (on screeshot) above if condition. image But i'm not shure what that change not breaks anything else. In my case - no viewport image when run currrent scene, just gray screen. When mode Render Direct To Screen disabled, all works fine (via ViewportTexture node)