godotengine / godot

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

Crashing when reducing nested viewport size component to 2 #59430

Open alexamy opened 2 years ago

alexamy commented 2 years ago

Godot version

v3.4.3.stable.arch_linux

System information

Arch Linux, GLES3, Nvidia GeForce GTX 1660 Super

Issue description

Expected: Setting nested viewport size to 2 doesnt crash the engine.

Actual: Setting nested viewport size to 2 crashes the engine with the following error:

❯ OpenGL ES 3.0 Renderer: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2
OpenGL ES Batching: ON

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

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v3.4.3.stable.arch_linux
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /usr/lib/libc.so.6(+0x42560) [0x7f466d582560] (??:0)
[2] /usr/bin/godot(+0x106c6cb) [0x55a1c358c6cb] (??:0)
[3] /usr/bin/godot(+0x106dead) [0x55a1c358dead] (??:0)
[4] /usr/bin/godot(+0x10a9f1f) [0x55a1c35c9f1f] (??:0)
[5] /usr/bin/godot(+0x2696c96) [0x55a1c4bb6c96] (??:0)
[6] /usr/bin/godot(+0x2ccb7fb) [0x55a1c51eb7fb] (??:0)
[7] /usr/bin/godot(+0x26868b6) [0x55a1c4ba68b6] (??:0)
[8] /usr/bin/godot(+0x26a5676) [0x55a1c4bc5676] (??:0)
[9] /usr/bin/godot(+0x8bbff2) [0x55a1c2ddbff2] (??:0)
[10] /usr/bin/godot(+0x836a9d) [0x55a1c2d56a9d] (??:0)
[11] /usr/lib/libc.so.6(+0x2d310) [0x7f466d56d310] (??:0)
[12] /usr/lib/libc.so.6(__libc_start_main+0x81) [0x7f466d56d3c1] (??:0)
[13] /usr/bin/godot(+0x84aa15) [0x55a1c2d6aa15] (??:0)
-- END OF BACKTRACE --

Steps to reproduce

  1. Open project
  2. Open player scene
  3. Select nested viewport Viewport
  4. Change its size component to 2

Minimal reproduction project

ViewportCameraBugMinimal.zip

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

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v3.5.beta.custom_build (cec7fc4ffeba4de992436ed9c7f8fe428c22a6b1)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] godots() [0x185be7a] (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/crash_handler_x11.cpp:55)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7fd32215f520] (??:0)
[3] CowData<RasterizerStorageGLES3::RenderTarget::Effects::MipMaps::Size>::get(int) const (/home/runner/work/GodotBuilds/GodotBuilds/godot/./core/cowdata.h:156 (discriminator 7))
[4] Vector<RasterizerStorageGLES3::RenderTarget::Effects::MipMaps::Size>::operator[](int) const (/home/runner/work/GodotBuilds/GodotBuilds/godot/./core/vector.h:87)
[5] RasterizerSceneGLES3::_blur_effect_buffer() (/home/runner/work/GodotBuilds/GodotBuilds/godot/drivers/gles3/rasterizer_scene_gles3.cpp:3215 (discriminator 8))
[6] RasterizerSceneGLES3::_render_mrts(RasterizerSceneGLES3::Environment*, CameraMatrix const&) (/home/runner/work/GodotBuilds/GodotBuilds/godot/drivers/gles3/rasterizer_scene_gles3.cpp:3468)
[7] RasterizerSceneGLES3::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/gles3/rasterizer_scene_gles3.cpp:4496)
[8] 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)
[9] VisualServerScene::render_camera(RID, RID, Vector2, RID) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_scene.cpp:2810 (discriminator 2))
[10] VisualServerViewport::_draw_3d(VisualServerViewport::Viewport*, ARVRInterface::Eyes) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:68)
[11] VisualServerViewport::_draw_viewport(VisualServerViewport::Viewport*, ARVRInterface::Eyes) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:109)
[12] VisualServerViewport::draw_viewports() (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_viewport.cpp:351)
[13] VisualServerRaster::draw(bool, double) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_raster.cpp:117 (discriminator 4))
[14] VisualServerWrapMT::draw(bool, double) (/home/runner/work/GodotBuilds/GodotBuilds/godot/servers/visual/visual_server_wrap_mt.cpp:122)
[15] Main::iteration() (/home/runner/work/GodotBuilds/GodotBuilds/godot/main/main.cpp:2292)
[16] OS_X11::run() (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/os_x11.cpp:3835)
[17] godots(main+0x343) [0x1852109] (/home/runner/work/GodotBuilds/GodotBuilds/godot/platform/x11/godot_x11.cpp:57)
[18] /lib/x86_64-linux-gnu/libc.so.6(+0x29fd0) [0x7fd322146fd0] (??:0)
[19] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7d) [0x7fd32214707d] (??:0)
[20] godots(_start+0x2e) [0x1851d0e] (??:?)
-- END OF BACKTRACE --
================================================================
pfertyk commented 2 years ago

I'd like to submit a fix. I'm not familiar with how the blur algorithm should work, I can see references to mip_maps[1] as well as mip_maps[0] and mip_maps[0].sizes[i + 1]. Therefore, I wasn't sure where to add a modification. The code references a mipmap size that doesn't exist. I've added a check just to the line where the actual i + 1 is used. If necessary, I can instead reduce the number of iterations (so i will never reach a wrong value). Let me know which one is better.