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

CharacterBody2D colliding with a CollisionObject queued for deletion causes a crash #92

Closed
jjanella opened this issue May 3, 2024 · 1 comment · Fixed by #95
Closed
Assignees
Labels
bug Something isn't working

Comments

@jjanella
Copy link

jjanella commented May 3, 2024

Description
CharacterBody2D colliding with a CollisionObject queued for deletion causes the project to crash

To Reproduce
Steps to reproduce the behavior:

  1. Install Rapier Engine
  2. Collide a CharactedBody2D with a node queued for deletion using move_and_slide()
  3. The project crashes

Expected behavior
CharacterBody2D colliding with CollisionObject queued for deletion should not cause a crash, and does not crash with the default physics engine.

Environment (please complete the following information):

  • OS: Arch Linux
  • Version 0.6.18
  • Godot Version 4.2.2
  • Type SIMD

Example project

Open a new project using Rapier physics and insert this code into a Node2D

extends Node2D

var plat: StaticBody2D
var body: CharacterBody2D

# To see whats going on go to debug -> visible collision shapes on
func _ready():
	# Add a character body to the scene
	add_char_body()
	
	plat = StaticBody2D.new()
	plat.add_child(CollisionPolygon2D.new())
	
	add_child(plat)


func add_char_body():
	body = CharacterBody2D.new()
	
	var cb = RectangleShape2D.new()
	cb.size = Vector2(10, 10)
	var shape = CollisionShape2D.new()
	shape.shape = cb
	
	body.add_child(shape)
	body.global_position = Vector2(150, 50)
	add_child(body)


func _physics_process(delta):
	body.velocity += Vector2(0, 100) * delta
	body.move_and_slide() # The line that causes the crash
	
	# Reset the platforms shape
	plat.get_child(0).queue_free()
	var pg = CollisionPolygon2D.new()
	pg.polygon = [Vector2(100, 100), Vector2(200, 100), Vector2(200, 110), Vector2(100, 110)]
	plat.add_child(pg)

Result from running Godot from the terminal:

ERROR: FATAL: Index p_index = 1 is out of bounds ((int)shapes.size() = 1).
   at: get_shape (src/servers/../bodies/rapier_collision_object_2d.h:94)

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v4.2.2.stable.arch_linux
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /usr/lib/libc.so.6(+0x3ce20) [0x7ab1bb658e20] (??:0)
[2] RapierBodyUtils2D::body_motion_recover(RapierSpace2D const&, RapierBody2D&, godot::Transform2D&, godot::Vector2 const&, float, godot::Vector2&) (??:0)
[3] RapierSpace2D::test_body_motion(RapierBody2D*, godot::Transform2D const&, godot::Vector2 const&, double, bool, bool, godot::PhysicsServer2DExtensionMotionResult*) const (??:0)
[4] RapierPhysicsServer2D::_body_test_motion(godot::RID const&, godot::Transform2D const&, godot::Vector2 const&, double, bool, bool, godot::PhysicsServer2DExtensionMotionResult*) const (??:0)
[5] godot::PhysicsServer2DExtension::register_virtuals<RapierPhysicsServer2D, godot::PhysicsServer2DExtension>()::{lambda(void*, void const* const*, void*)#112}::_FUN(void*, void const* const*, void*) (??:0)
[6] /usr/bin/godot(+0x30a57bf) [0x5ef85a8247bf] (??:?)
[7] /usr/bin/godot(+0x238bbc8) [0x5ef859b0abc8] (??:?)
[8] /usr/bin/godot(+0x238c3ce) [0x5ef859b0b3ce] (??:?)
[9] /usr/bin/godot(+0x1b1662) [0x5ef857930662] (??:?)
[10] /usr/bin/godot(+0x3b86e6) [0x5ef857b376e6] (??:?)
[11] /usr/bin/godot(+0x2a8adf) [0x5ef857a27adf] (??:?)
[12] /usr/bin/godot(+0x1c9256c) [0x5ef85941156c] (??:?)
[13] /usr/bin/godot(+0x23c2538) [0x5ef859b41538] (??:?)
[14] /usr/bin/godot(+0x384fe98) [0x5ef85afcee98] (??:?)
[15] /usr/bin/godot(+0x1cad4f0) [0x5ef85942c4f0] (??:?)
[16] /usr/bin/godot(+0x1cdd267) [0x5ef85945c267] (??:?)
[17] /usr/bin/godot(+0x1ce33f1) [0x5ef8594623f1] (??:?)
[18] /usr/bin/godot(+0x17d581) [0x5ef8578fc581] (??:?)
[19] /usr/bin/godot(+0x90c2e) [0x5ef85780fc2e] (??:?)
[20] /usr/lib/libc.so.6(+0x25d4a) [0x7ab1bb641d4a] (??:0)
[21] /usr/lib/libc.so.6(__libc_start_main+0x8c) [0x7ab1bb641e0c] (??:0)
[22] /usr/bin/godot(+0x9d8a5) [0x5ef85781c8a5] (??:?)
-- END OF BACKTRACE --
================================================================```
@jjanella jjanella added the bug Something isn't working label May 3, 2024
@jjanella
Copy link
Author

jjanella commented May 3, 2024

I should note this doesn't crash with regular rigid body collisions, I believe it is unique to the move_and_slide() method of CharacterBody2D.

@Ughuuu Ughuuu self-assigned this May 4, 2024
@Ughuuu Ughuuu closed this as completed in #95 May 4, 2024
Ughuuu added a commit that referenced this issue May 4, 2024
Ughuuu added a commit that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants