Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when move_and_slide_with_snap is called #31753

Closed
hodgerti opened this issue Aug 29, 2019 · 6 comments
Closed

Crash when move_and_slide_with_snap is called #31753

hodgerti opened this issue Aug 29, 2019 · 6 comments

Comments

@hodgerti
Copy link

hodgerti commented Aug 29, 2019

Godot version:
3.1.1 Stable

OS/device including version:
Windows 10 64 bit

Issue description:

Background:
In my game I use two threads to load things for a new level before switching. One thread is used to load resources (resource_queue.gd) before the scene is instanced, and the other is used to run initialization functions for the new level after it is instanced and parented (level_loader.gd).

The two level switching threads are facilitated by my Main scene, who also owns the levels. This Main scene also owns the Player, who is simply switched from level to level and never deleted.

When Main switches levels it does it like this:

  1. A new level's resources are loaded
  2. The new level is instanced
  3. The new level is paused while the current level remains unpaused
  4. The new level is added to Main
  5. The new level gives it's initialization function to level_loader via _ready()
  6. Upon level_loader finishing running the initialization function the old level is free'd, then the new level is unpaused and given a reference to the player (to be used for things like the Camera and enemy AI).
  7. The new level becomes the current level.

The Issue:
The game crashes when move_and_slide_with_snap() is called by the Player. After the new level is done with its initialization via level_loader, it doesn't have an issues with crashing.

Note:
Sometimes it only crashes upon colliding with the map.
Sometimes it doesn't crash at all and just jitters widely until finished initializing.

Here is a stack trace:

ERROR: CollisionObject2DSW::is_shape_set_as_disabled: FATAL: Index p_idx=7 out of size (shapes.size()=1)
   At: d:\program files\godot\servers\physics_2d\collision_object_2d_sw.h:151
CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] CollisionObject2DSW::is_shape_set_as_disabled (d:\program files\godot\servers\physics_2d\collision_object_2d_sw.h:151)
[1] Space2DSW::_cull_aabb_for_body (d:\program files\godot\servers\physics_2d\space_2d_sw.cpp:492)
[2] Space2DSW::test_body_motion (d:\program files\godot\servers\physics_2d\space_2d_sw.cpp:769)
[3] Physics2DServerSW::body_test_motion (d:\program files\godot\servers\physics_2d\physics_2d_server_sw.cpp:1056)
[4] Physics2DServerWrapMT::body_test_motion (d:\program files\godot\servers\physics_2d\physics_2d_server_wrap_mt.h:262)
[5] KinematicBody2D::move_and_collide (d:\program files\godot\scene\2d\physics_body_2d.cpp:1206)
[6] KinematicBody2D::move_and_slide_with_snap (d:\program files\godot\scene\2d\physics_body_2d.cpp:1340)
[7] MethodBind7R<KinematicBody2D,Vector2,Vector2 const & __ptr64,Vector2 const & __ptr64,Vector2 const & __ptr64,bool,int,float,bool>::call (d:\program files\godot\core\method_bind_ext.gen.inc:1205)
[8] Object::call (d:\program files\godot\core\object.cpp:942)
[9] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[10] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1073)
[11] GDScriptInstance::call (d:\program files\godot\modules\gdscript\gdscript.cpp:1175)
[12] Object::call (d:\program files\godot\core\object.cpp:921)
[13] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[14] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1078)
[15] GDScriptInstance::call (d:\program files\godot\modules\gdscript\gdscript.cpp:1175)
[16] Object::call (d:\program files\godot\core\object.cpp:921)
[17] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[18] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1078)
[19] GDScriptInstance::call_multilevel (d:\program files\godot\modules\gdscript\gdscript.cpp:1191)
[20] Node::_notification (d:\program files\godot\scene\main\node.cpp:63)
[21] Node::_notificationv (d:\program files\godot\scene\main\node.h:46)
[22] CanvasItem::_notificationv (d:\program files\godot\scene\2d\canvas_item.h:166)
[23] Node2D::_notificationv (d:\program files\godot\scene\2d\node_2d.h:38)
[24] CollisionObject2D::_notificationv (d:\program files\godot\scene\2d\collision_object_2d.h:39)
[25] PhysicsBody2D::_notificationv (d:\program files\godot\scene\2d\physics_body_2d.h:43)
[26] KinematicBody2D::_notificationv (d:\program files\godot\scene\2d\physics_body_2d.h:290)
[27] Object::notification (d:\program files\godot\core\object.cpp:954)
[28] SceneTree::_notify_group_pause (d:\program files\godot\scene\main\scene_tree.cpp:971)
[29] SceneTree::iteration (d:\program files\godot\scene\main\scene_tree.cpp:474)
[30] Main::iteration (d:\program files\godot\main\main.cpp:1862)
[31] OS_Windows::run (d:\program files\godot\platform\windows\os_windows.cpp:2819)
[32] widechar_main (d:\program files\godot\platform\windows\godot_windows.cpp:151)
[33] _main (d:\program files\godot\platform\windows\godot_windows.cpp:173)
[34] main (d:\program files\godot\platform\windows\godot_windows.cpp:185)
[35] __scrt_common_main_seh (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253)
[36] BaseThreadInitThunk
-- END OF BACKTRACE --

And here is another similar one:

ERROR: CowData<class RID>::get: FATAL: Index p_index=0 out of size (size()=0)
   At: D:\Program Files\godot\core/cowdata.h:151
CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] CowData<RID>::get (d:\program files\godot\core\cowdata.h:151)
[1] Vector<RID>::operator[] (d:\program files\godot\core\vector.h:85)
[2] VSet<RID>::_find_exact (d:\program files\godot\core\vset.h:85)
[3] VSet<RID>::has (d:\program files\godot\core\vset.h:114)
[4] Body2DSW::has_exception (d:\program files\godot\servers\physics_2d\body_2d_sw.h:170)
[5] Space2DSW::_cull_aabb_for_body (d:\program files\godot\servers\physics_2d\space_2d_sw.cpp:490)
[6] Space2DSW::test_body_ray_separation (d:\program files\godot\servers\physics_2d\space_2d_sw.cpp:566)
[7] Physics2DServerSW::body_test_ray_separation (d:\program files\godot\servers\physics_2d\physics_2d_server_sw.cpp:1066)
[8] Physics2DServerWrapMT::body_test_ray_separation (d:\program files\godot\servers\physics_2d\physics_2d_server_wrap_mt.h:268)
[9] KinematicBody2D::separate_raycast_shapes (d:\program files\godot\scene\2d\physics_body_2d.cpp:1169)
[10] KinematicBody2D::move_and_slide (d:\program files\godot\scene\2d\physics_body_2d.cpp:1269)
[11] KinematicBody2D::move_and_slide_with_snap (d:\program files\godot\scene\2d\physics_body_2d.cpp:1333)
[12] MethodBind7R<KinematicBody2D,Vector2,Vector2 const & __ptr64,Vector2 const & __ptr64,Vector2 const & __ptr64,bool,int,float,bool>::call (d:\program files\godot\core\method_bind_ext.gen.inc:1205)
[13] Object::call (d:\program files\godot\core\object.cpp:942)
[14] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[15] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1073)
[16] GDScriptInstance::call (d:\program files\godot\modules\gdscript\gdscript.cpp:1175)
[17] Object::call (d:\program files\godot\core\object.cpp:921)
[18] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[19] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1078)
[20] GDScriptInstance::call (d:\program files\godot\modules\gdscript\gdscript.cpp:1175)
[21] Object::call (d:\program files\godot\core\object.cpp:921)
[22] Variant::call_ptr (d:\program files\godot\core\variant_call.cpp:1053)
[23] GDScriptFunction::call (d:\program files\godot\modules\gdscript\gdscript_function.cpp:1078)
[24] GDScriptInstance::call_multilevel (d:\program files\godot\modules\gdscript\gdscript.cpp:1191)
[25] Node::_notification (d:\program files\godot\scene\main\node.cpp:63)
[26] Node::_notificationv (d:\program files\godot\scene\main\node.h:46)
[27] CanvasItem::_notificationv (d:\program files\godot\scene\2d\canvas_item.h:166)
[28] Node2D::_notificationv (d:\program files\godot\scene\2d\node_2d.h:38)
[29] CollisionObject2D::_notificationv (d:\program files\godot\scene\2d\collision_object_2d.h:39)
[30] PhysicsBody2D::_notificationv (d:\program files\godot\scene\2d\physics_body_2d.h:43)
[31] KinematicBody2D::_notificationv (d:\program files\godot\scene\2d\physics_body_2d.h:290)
[32] Object::notification (d:\program files\godot\core\object.cpp:954)
[33] SceneTree::_notify_group_pause (d:\program files\godot\scene\main\scene_tree.cpp:971)
[34] SceneTree::iteration (d:\program files\godot\scene\main\scene_tree.cpp:474)
[35] Main::iteration (d:\program files\godot\main\main.cpp:1862)
[36] OS_Windows::run (d:\program files\godot\platform\windows\os_windows.cpp:2819)
[37] widechar_main (d:\program files\godot\platform\windows\godot_windows.cpp:151)
[38] _main (d:\program files\godot\platform\windows\godot_windows.cpp:173)
[39] main (d:\program files\godot\platform\windows\godot_windows.cpp:185)
[40] __scrt_common_main_seh (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253)
[41] BaseThreadInitThunk
-- END OF BACKTRACE --

Steps to reproduce:

  1. Start the game
  2. Using 'w', 'a', 's', 'd', 'space' jump up into the box with 'Barren' next to it (you can climb walls :) )
  3. Press 'f' to load the next level
  4. You should make some kind of collision with the map right after instancing and parenting the new level and while level_loader is still running the initialization function.
  5. If it doesn't happen the first time repeat steps 1-4 a couple times to see if you can trigger a crash.

Minimal reproduction project:
scuffed_game_crippled.zip

Where to look in the game files:
res::/scripts/main.gd - look for my threads which are created in _ready()
res:://levels/level_template - look for the post_function() in _ready()

@hodgerti hodgerti changed the title Godot crashes due to Kinematic 2D Collision when move_and_slide is called Godot crashes when move_and_slide is called Aug 29, 2019
@hodgerti hodgerti changed the title Godot crashes when move_and_slide is called Godot sometimes crashes when move_and_slide_with_snap is called Aug 29, 2019
@hodgerti hodgerti changed the title Godot sometimes crashes when move_and_slide_with_snap is called Crash when move_and_slide_with_snap is called Aug 29, 2019
@KoBeWi
Copy link
Member

KoBeWi commented Aug 29, 2019

The first stack trace looks similar to #29364

@hodgerti
Copy link
Author

hodgerti commented Aug 29, 2019

@KoBeWi Thanks for linking the other issue. When I get home in a bit I'll delve into. At the moment, it looks like if I take out the call to direct space state (space_state.intersect_shape(shape_query, 1) in res://scenes/levels/level_template.gd) that I have no more issues. The function where this call is made is called inside my level loader thread (res://scripts/loading/level_loader.gd). I made a post dealing with the same bug in my code on Godot Q&A: https://godotengine.org/qa/50988/how-does-physics2ddirectspacestate-handle-queries

@hodgerti
Copy link
Author

This issue is being discussed here: #30700
Here is a demo of some random errors that happen when running threads (you'll need to run it a few times):
scuffed_game_crippled.zip

@qarmin
Copy link
Contributor

qarmin commented Dec 26, 2019

Still happens with beta 4, and I have also with Ubsan Sanitizer this messages

servers/physics_2d/space_2d_sw.cpp:486:65: runtime error: downcast of address 0x614000091850 which does not point to an object of type 'Body2DSW'
0x614000091850: note: object is of type 'Area2DSW'
 be be be be  28 a7 45 16 00 00 00 00  b3 07 00 00 00 00 00 00  50 18 09 00 40 61 00 00  73 09 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'Area2DSW'
servers/physics_2d/space_2d_sw.cpp:486:81: runtime error: member call on address 0x614000091850 which does not point to an object of type 'Body2DSW'
0x614000091850: note: object is of type 'Area2DSW'
 be be be be  28 a7 45 16 00 00 00 00  b3 07 00 00 00 00 00 00  50 18 09 00 40 61 00 00  73 09 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'Area2DSW'
core/cowdata.h:128:12: runtime error: load of misaligned address 0xbebebebe000008ff for type 'uint32_t', which requires 4 byte alignment
0xbebebebe000008ff: note: pointer points here

@KoBeWi
Copy link
Member

KoBeWi commented Nov 18, 2020

Can anyone still reproduce this bug in Godot 3.2.3 or any later release?

I tried the MRP few times and nothing happened.

@qarmin qarmin added this to the 4.0 milestone Jan 2, 2021
@qarmin
Copy link
Contributor

qarmin commented Jan 2, 2021

I tried to reproduce it but looks that issue is fixed

@qarmin qarmin closed this as completed Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants