Browse Source

Fix bug in CollisionPolygon2D and ToluaToPODVector<Vector2>.

aster2013 11 years ago
parent
commit
63af574730

+ 3 - 1
Source/Engine/LuaScript/ToluaUtils.cpp

@@ -201,13 +201,15 @@ template<> void* ToluaToPODVector<Vector2>(lua_State* L, int narg, void* def)
     static PODVector<Vector2> result;
     static PODVector<Vector2> result;
     result.Clear();
     result.Clear();
 
 
+    tolua_Error tolua_err;
+
     int length = lua_objlen(L, narg);
     int length = lua_objlen(L, narg);
     for (int i = 1; i <= length; ++i)
     for (int i = 1; i <= length; ++i)
     {
     {
         lua_pushinteger(L, i);
         lua_pushinteger(L, i);
         lua_gettable(L, narg);
         lua_gettable(L, narg);
 
 
-        if (!lua_isnumber(L, -1))
+        if (!tolua_isusertype(L, -1, "Vector2", 0, &tolua_err))
         {
         {
             lua_pop(L, 1);
             lua_pop(L, 1);
             return 0;
             return 0;

+ 3 - 0
Source/Engine/Urho2D/CollisionPolygon2D.cpp

@@ -83,6 +83,9 @@ void CollisionPolygon2D::ApplyNodeWorldScale()
 void CollisionPolygon2D::RecreateFixture()
 void CollisionPolygon2D::RecreateFixture()
 {
 {
     ReleaseFixture();
     ReleaseFixture();
+    
+    if (vertices_.Size() < 3)
+        return;
 
 
     PODVector<b2Vec2> b2Vertices;
     PODVector<b2Vec2> b2Vertices;
     unsigned count = vertices_.Size();
     unsigned count = vertices_.Size();