godot-rapier-2d icon indicating copy to clipboard operation
godot-rapier-2d copied to clipboard

`Shape not found` error when assign polygon to CollisionPolygon2D after update to version 0.8.7

Open 949886 opened this issue 1 year ago • 4 comments

Describe the bug

Screenshot - 2024-10-18 21 11 13

image

It worked fine before I updated it to the new version.

To Reproduce

class_name RigidBodyGenerator
extends RigidBody2D

@onready var sprite = $Sprite2D

func _ready() -> void:
	var bitmap = BitMap.new()
	bitmap.create_from_image_alpha(sprite.texture.get_image())
	var polys = bitmap.opaque_to_polygons(Rect2(Vector2.ZERO, sprite.texture.get_size()), 0.5)
	
	for poly in polys:
		var collision_polygon = CollisionPolygon2D.new()
		collision_polygon.build_mode = CollisionPolygon2D.BUILD_SEGMENTS
		collision_polygon.polygon = poly
		add_child(collision_polygon)

		# Generated polygon will not take into account the half-width and half-height offset
		# of the image when "centered" is on. So move it backwards by this amount so it lines up.
		if sprite.centered:
			var half_size = bitmap.get_size() / 2
			collision_polygon.position -= Vector2(half_size.x, half_size.y)

Expected behavior

No errors.

Environment:

  • OS: Windows
  • Version: 0.8.7
  • Godot Version: 4.3
  • Type: 2d

Example project(zip)

game.zip

949886 avatar Oct 18 '24 13:10 949886

Can you also try in 0.8.8?

Ughuuu avatar Oct 18 '24 14:10 Ughuuu

Can you also try in 0.8.8?

I tried it in version 0.8.8 and the errors disappeared, but the collide behavior is different from before. Is that normal?

image
This is the old one:

image

949886 avatar Oct 19 '24 03:10 949886

Ok, so now errors dissapear but the behaviour seems wrong. Will investigate the behaviour for collisions.

Ughuuu avatar Oct 19 '24 12:10 Ughuuu

I'm receiving this as well in 0.8.8 and 0.8.9

  src\shapes\rapier_convex_polygon_shape.rs:111 - ConvexPolygon shape points changed from size 6 to 0
  src\rapier_wrapper\shape.rs:296 - Shape not found
  src\shapes\rapier_convex_polygon_shape.rs:111 - ConvexPolygon shape points changed from size 6 to 0
  src\rapier_wrapper\shape.rs:296 - Shape not found

asciifaceman avatar Jan 01 '25 03:01 asciifaceman

No longer spams errors, fixed. Reopen if still happens. It lags a bit but each shape has way too many vertices.

Ughuuu avatar Oct 31 '25 16:10 Ughuuu

So there's kind of two bugs here-- one was the error spam, the other was the extra contact points showing up. The error spam is gone now, and the other bug was fixed by https://github.com/appsinacup/godot-rapier-physics/pull/412

dog-molecule avatar Oct 31 '25 16:10 dog-molecule