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

Convex decomposing failed with CollisionPolygon2D PackedVector2Array size < 3 #45724

Closed
Tracked by #45334
TotCac opened this issue Feb 5, 2021 · 15 comments · Fixed by #46668
Closed
Tracked by #45334

Convex decomposing failed with CollisionPolygon2D PackedVector2Array size < 3 #45724

TotCac opened this issue Feb 5, 2021 · 15 comments · Fixed by #46668

Comments

@TotCac
Copy link

TotCac commented Feb 5, 2021

Godot version:
1f7f27e

OS/device including version:
Windows 10 64bits
Nvidia GTX 1060 (driver 461.40)

Issue description:
While using CollisionPolygon2D with PackedVector2Array size < 3, editor show an error (not only the warning icon)

ERROR: Convex decomposing failed!
at: decompose_polygon_in_convex (core/math/geometry_2d.cpp:53)

Steps to reproduce:
Just add node CollisionPolygon2D

Minimal reproduction project:
bugreport.zip

@TotCac
Copy link
Author

TotCac commented Feb 5, 2021

I post a similar issue while ago
#19558

@jjmontes
Copy link

jjmontes commented Mar 4, 2021

With Godot version 3.2.4 RC 3 over Ubuntu 18.04.5 LTS it also happens

In the attached project you can test. You just have to open the Node2D.tscn scene, select the CollisionShape2D node, and in the node properties, change Shape to ConcavePolygonShape2D or ConvexPolygonShape2D and the editor closes.

CollisionBug.zip

NOTE: In Godot 3.2.4 Beta 5 this error does not occur

@pouleyKetchoupp
Copy link
Contributor

@jjmontes I've fixed ConvexPolygonShape2D but I can't reproduce a crash with ConcavePolygonShape2D. Could you please confirm this issue affects convex shapes only or let me know the exact repro for concave shapes?

@Sslaxx
Copy link

Sslaxx commented Sep 8, 2021

Finding this error is occurring in 3.3.3.

@pouleyKetchoupp
Copy link
Contributor

@Sslaxx Could you share your setup in a minimal project? It would help finding what case I missed with the last fix.

@Sslaxx
Copy link

Sslaxx commented Sep 8, 2021

Minimal, afraid not - not my work and I'm unsure of how to separate it. https://github.com/coderman64/flow-engine/tree/working - @coderman64

@pouleyKetchoupp
Copy link
Contributor

That helps, thanks! What are the repro steps?

@Sslaxx
Copy link

Sslaxx commented Sep 8, 2021

For me, the errors happened when attempting to resize the window.

@pouleyKetchoupp
Copy link
Contributor

@Sslaxx Given the project assets, it seems these errors could be related to tilemaps, but I wasn't able to reproduce anything. Please open a separate issue with more details if you see it again or can give a bit more details about the context.

@golddotasksquestions
Copy link

@pouleyKetchoupp

I cannot confirm this is related to TileMaps. I'm having the same issue and it's very easy for me to replicate it without TileMap:

extends Node2D

onready var line = $Line2D
onready var collision_poly = $Area2D/CollisionPolygon2D

func _process(delta):
	if Input.is_action_pressed("LMB"):
		line.add_point(get_global_mouse_position())
	if Input.is_action_just_released("LMB"):
		collision_poly.polygon = line.points

image

Minimal Reproduction Project:
convex_polygon_decomposition_bug.zip

@kleonc
Copy link
Member

kleonc commented Nov 5, 2021

@golddotasksquestions Seems like the reason of the convex decomposing failing in your example is the repetition of the same point (which happens when you didn't move mouse between consecutive _process() calls while holding LMB).

So even with your code I could draw a concave shape which was decomposed successfully (just have to be fast and precise enough):
firefox_6I7YzJPBjG

Disallowing such points should help for now:

func _process(delta):
	if Input.is_action_pressed("LMB"):
		var p = get_global_mouse_position()
		if line.get_point_count() == 0 or line.get_point_position(line.get_point_count() - 1) != p:
			line.add_point(p)
	if Input.is_action_just_released("LMB"):
		collision_poly.polygon = line.point

It's easy to draw complex shape after such change:
Godot_v3 4-rc3_win64_n3raoZfoJK

A proof showing duplicates are the cause (after a delay after releasing LMB removing duplicated points and reassigning them to the CollisionPolygon2D.polygon makes convex decomposing not fail):

func _process(delta):
	if Input.is_action_pressed("LMB"):
		var p = get_global_mouse_position()
		line.add_point(p)
	if Input.is_action_just_released("LMB"):
		var points = line.points
		line.points = []

		collision_poly.polygon = points

		yield(get_tree().create_timer(0.5), "timeout")

		var i = 0
		for j in range(1, points.size()):
			if points[j - 1] != points[j]:
				points[i] = points[j]
				i += 1
		points.resize(i)
		collision_poly.polygon = points

HdgZX2qq04

@golddotasksquestions
Copy link

golddotasksquestions commented Nov 5, 2021

@kleonc
Oh wow! What a great find! I would not have figured this out.

Still I think this should be more robust. If they are needed, I think these checks should happen under the hood.

@SteveSmith16384
Copy link

I'm getting this error when I call opaque_to_polygons() on a bitmap created from a specific png image I have. I'm using 3.4.2. It's a polygon with 85 points (i.e. more than 3), and I've checked for duplicate points, but it still happens.

@Calinou
Copy link
Member

Calinou commented Feb 7, 2022

I'm getting this error when I call opaque_to_polygons() on a bitmap created from a specific png image I have. I'm using 3.4.2. It's a polygon with 85 points (i.e. more than 3), and I've checked for duplicate points, but it still happens.

Please open a new issue with a minimal reproduction project attached.

Edit: Issue opened: #57789

@dimkauzh
Copy link

dimkauzh commented Sep 6, 2022

@pouleyKetchoupp

I cannot confirm this is related to TileMaps. I'm having the same issue and it's very easy for me to replicate it without TileMap:

extends Node2D

onready var line = $Line2D
onready var collision_poly = $Area2D/CollisionPolygon2D

func _process(delta):
	if Input.is_action_pressed("LMB"):
		line.add_point(get_global_mouse_position())
	if Input.is_action_just_released("LMB"):
		collision_poly.polygon = line.points

image

Minimal Reproduction Project: convex_polygon_decomposition_bug.zip

for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.