ASSERT in b2PolygonShape::Set / vertices order
Posted: Sun Feb 23, 2014 10:52 pm
Hello, I think there is a problem with vertices export/saving order. Or I'm really very tired 
I have created some "magic" project with RUBE, which does not works after export to *.cpp or *.json. Just simple box with two fixtures (attached in zip file).
Project opens in RUBE, and works in player. After export to cpp and json, not works on my target project with Box2d 2.3.0.
Box2d reports exception:
Other projects are working, so the problem is only with this one.
After some investigation I have noticed differences in polygon vertices order of scene exported from RUBE:
JSON file
--------------------------------
C++ file
--------------------------------
As you see, order of vertices are the same after export for *.cpp and *.json. However in RUBE are somehow inverted:
RUBE file
--------------------------------
But even if I reorder vectors in my project, to match order in rube project file:
(changed index order to: 2,3,0,1).
This still does not work. However, RUBE opens this file and "plays". Maybe RUBE somehow reorder vertices on each project load in some validation phase, and this validation is not executed before scene export or something?
Please help!

I have created some "magic" project with RUBE, which does not works after export to *.cpp or *.json. Just simple box with two fixtures (attached in zip file).
Project opens in RUBE, and works in player. After export to cpp and json, not works on my target project with Box2d 2.3.0.
Box2d reports exception:
Code: Select all
void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
158: // Polygon is degenerate.
b2Assert(false);
After some investigation I have noticed differences in polygon vertices order of scene exported from RUBE:
JSON file
--------------------------------
Code: Select all
"vertices" :
{
"x" :
[
0.05443939194083214,
-0.04991665109992027,
-0.06269122660160065,
0.04166480526328087
],
"y" :
[
-0.08557727187871933,
-0.004275797400623560,
-0.02067285589873791,
-0.1019743308424950
]
}
--------------------------------
Code: Select all
vs[0].Set(5.443939194083214e-02f, -8.557727187871933e-02f);
vs[1].Set(-4.991665109992027e-02f, -4.275797400623560e-03f);
vs[2].Set(-6.269122660160065e-02f, -2.067285589873791e-02f);
vs[3].Set(4.166480526328087e-02f, -1.019743308424950e-01f);
RUBE file
--------------------------------
Code: Select all
"vertices" :
{
"x" :
[
-0.06269122660160065,
0.04166480526328087,
0.05443939194083214,
-0.04991665109992027
],
"y" :
[
-0.02067285589873791,
-0.1019743308424950,
-0.08557727187871933,
-0.004275797400623560
]
}
Code: Select all
vs[0].Set(-6.269122660160065e-02f, -2.067285589873791e-02f);
vs[1].Set(4.166480526328087e-02f, -1.019743308424950e-01f);
vs[2].Set(5.443939194083214e-02f, -8.557727187871933e-02f);
vs[3].Set(-4.991665109992027e-02f, -4.275797400623560e-03f);
This still does not work. However, RUBE opens this file and "plays". Maybe RUBE somehow reorder vertices on each project load in some validation phase, and this validation is not executed before scene export or something?
Please help!