Custom Polygon Collision Error in Xcode

Photics

  • *
  • Posts: 719
So, I created a nice 8-point polygon for my paddle. It runs without problem in Flash. But once I try to test the game on my iOS through Xcode, I get the following error...


Quote
0x0001b2e0  <+0720>  andeq   r11, r7, r0, lsr #2   Thread 2: Program received signal: "SIGABRT"

I think the problem might be related to this message...

Quote
[7165:2203] Reading a Sprite...
2012-01-09 21:07:10.247 AppScaffold[7165:2203] sprite7-0-0
2012-01-09 21:07:10.252 AppScaffold[7165:2203] Reading an Actor...
2012-01-09 21:07:10.257 AppScaffold[7165:2203] Reading a Sprite...
Assertion failed: (area > 1.19209290e-7F), function ComputeCentroid, file /Users/jon/Desktop/stencyl/plaf/ios/exporter/../physics/Box2D/Collision/Shapes/b2PolygonShape.cpp, line 116.
[Switching to process 8963 thread 0x2303]
[Switching to process 8963 thread 0x2303]
(gdb)

If it's looking for... /Users/jon ...it's not going to find it on my Mac Mini  :D

At first I thought this was a polygon issue. I thought that I might have used too many points. Now I'm thinking this might be something else.
Michael Garofalohttp://photics.com – Author of The Interactive Stencyl Textbook 8)

Jon

  • *
  • Posts: 17524
I'd like to play around with this exact shape. Could you e-mail me the project folder zipped up (it's under games)?

Photics

  • *
  • Posts: 719
I'd like to play around with this exact shape. Could you e-mail me the project folder zipped up (it's under games)?

I sent an email to you. Now you get to see my awesome particle system.
Oooooohhhhh  :o

Heh, it's still a work in progress.  :P
Michael Garofalohttp://photics.com – Author of The Interactive Stencyl Textbook 8)

Jon

  • *
  • Posts: 17524
Still looking at it - it's a Box2D thing, and I think it might be resolving this shape as concave, even though to my eye, it isn't, and it works fine in Flash, which is odd since they both use the same Box2D codebase...

To solve it, pull points #5 and #2 in the polygon to the left and right respectively. The x values that worked were 52 and 12 (4 pixels off from the original values)

Nice particle effect, and this is going to sound strange, but you are very immaculate with your projects (a good thing!).

Alexin

  • *
  • Posts: 3132
I investigated a bit and I suspect this is either a Box2D bug, numerical inaccuracy due to hardware limitations, or both. Since the problem happens only with iOS, I'm inclined to the second cause, until proven otherwise.



Quote from: Jon
Nice particle effect, and this is going to sound strange, but you are very immaculate with your projects (a good thing!).
I cleanup the game's folder manually, delete every unused resource, make sure there are no extra spaces/tabs/lines in code behaviors, organize the tabs according to the resource usage, from let to right, etc.
"Find the fun"
alexin@stencyl.com

Photics

  • *
  • Posts: 719
Nice particle effect, and this is going to sound strange, but you are very immaculate with your projects (a good thing!).

Ha, is that because I put icons on my behaviors?  :D
...or is it because I separate my iOS/Flash code?  8)

I think that's a great compliment. If you like how my unfinished project is setup, then I think that means I'm moving in the right direction for the textbook.

I moved the polygon points around. It's strange how it works sometimes and not others. I was watching the concave warning... but the shape isn't concave, so this is a weird bug. I'm thinking that I might change the paddle to a more classic design.

Michael Garofalohttp://photics.com – Author of The Interactive Stencyl Textbook 8)

Jon

  • *
  • Posts: 17524
Particularly the first one - it's very rare to see icons put on all behaviors, much less icons you made yourself (?).

As you can imagine through all the games that get sent my way for debugging (hundreds), the vast majority are seas of hammer icons with lazy names (sorry if I offend anyone!)

Jon

  • *
  • Posts: 17524
Alexin had some ideas about the cause of the shape bug. It's more just for your curiosity - it's pretty technical/mathematical.


Quote from: Alexin
1. The area (1.19209290e-7F) isn't negative but near zero.
Obviously the area of the shape isn't so small, but I suspect the area in question belongs to the triangle formed by the vertices #4, #5 and #6.

2. The error is thrown from b2CollisionShape.ComputeCentroid which uses the "signed area" algorithm.
In reality there's no such thing as a negative area (!), but there's an algorithm that determines the convexity of a polygon by computing a particular value. The absolute value is equal to the area of the polygon, while the sign indicates its convexity.

3. Expanding the shape a little fixes the problem (bigger area).
Note this consequently increases the area of the triangle referred in 1.


4. The problem happens only in iOS.
Numerical inaccuracies? Are the simulator and/or device really limited to that point?

Photics

  • *
  • Posts: 719
Particularly the first one - it's very rare to see icons put on all behaviors, much less icons you made yourself (?).

Those are the icons included with Stencyl. I thought that's what they were for. I think it's OK for me to send those icons back to you. Yet, I don't know if I would use those icons if I uploaded or sold StencylWorks templates.

Quote from: Jon
Alexin had some ideas about the cause of the shape bug. It's more just for your curiosity - it's pretty technical/mathematical.

Heh, yeah... that looks technical. Is this something that's going to be improved? I noticed on this page...

http://community.stencyl.com/index.php/topic,6345.0.html

...there's a image of something that looks like a tree. It has convex shape. Are convex shapes going to be added later?

I recently had a problem with Flash recently that seems similar to this one. I was trying to calculate the vector between two points. But because those points were so close together, I wasn't getting smooth results. I fixed the problem by running the calculation less frequently, creating space between the two points.

So, back to Stencyl, if it doesn't work on iOS but it works on Flash... maybe this is a retina display thing. I thought it was strange to be working on a smaller graphic and not a larger one that would be scaled down later.
Michael Garofalohttp://photics.com – Author of The Interactive Stencyl Textbook 8)

mukowAPPS

  • Posts: 78
hey photics, the concave shapes are for tiles only because they are stationary and never move (as far as i understand). even though you still get the little "concave shapes not allowed" when making the polygon, it still creates it and builds it. i tested it on ios using the preview on device and it worked. i did not try adhoc though.

Alexin

  • *
  • Posts: 3132
Exactly, tiles support concave shapes but actors don't.
"Find the fun"
alexin@stencyl.com

Jon

  • *
  • Posts: 17524
To be clear, concave shapes are never supported in Box2D - the tile case works because they're not actually polygons but actually a set of line shapes. But lines aren't move, which is why we can't use them for normal actors.

You can triangulate the shape (break it up into a bunch of triangles), but that can lead to unintended consequences too.