OpenGL problem of textured map in mosaic!

I'm having the following problem. Some tiles on my map are badly drawn, I think it could be an indexing problem. Here is the exit:

Map output

Some tiles just look bad !! I'm not sure what I'm doing wrong with my code, so please take a look.

This is where I build the map:

override SetData (GLfloat data *, unsigned int counter, GLfloat value)
{
data[counter] = value;
}

cancel uSetData (data int * without sign, int counter unsigned, int value unsigned)
{
data[counter] = value;
}

void Layer_Build (Layer * layer)
{
unsigned int size = layer-> width * layer-> height;

unsigned int vDataCounter = size * 12,
uDataCounter = size * 8,
iDataCounter = size * 6,
cDataCounter = size * 16;

GLfloat * vData = (GLfloat *) calloc (vDataCounter, sizeof (GLfloat));
GLfloat * uData = (GLfloat *) calloc (uDataCounter, sizeof (GLfloat));
unsigned int * iData = (unsigned int *) calloc (iDataCounter, sizeof (unsigned int));
GLfloat * cData = (GLfloat *) calloc (cDataCounter, sizeof (GLfloat));

unsigned int vCounter = 0,
uCounter = 0,
iCounter = 0,
cCounter = 0;

for (without int sign y = 0; and < layer->height; and ++)
{
for (without sign int x = 0; x < layer->width; x ++)
{
struct Tile tile = Layer_GetTile (layer, x, y);

yes (tile.gid! = 0)
{
Tileset * tileset = Tileset_Find (layer-> terrain, tile.gid);

Rect cell = Tileset_Cell (tileset, tile.gid);

Vector2 auxPos;
auxPos.x = x * (float) tileset-> width;
auxPos.y = y * - (float) tileset-> height;

float cellWidth = (float) tileset-> width,
cellHeight = (float) tileset-> height;

SetData (vData, vCounter, -cellWidth + auxPos.x);
SetData (vData, vCounter + 1, -cellHeight + auxPos.y);
SetData (vData, vCounter + 2, layer-> depth);

SetData (vData, vCounter + 3, cellWidth + auxPos.x);
SetData (vData, vCounter + 4, -cellHeight + auxPos.y);
SetData (vData, vCounter + 5, layer-> depth);

SetData (vData, vCounter + 6, cellWidth + auxPos.x);
SetData (vData, vCounter + 7, cellHeight + auxPos.y);
SetData (vData, vCounter + 8, layer-> depth);

SetData (vData, vCounter + 9, -cellWidth + auxPos.x);
SetData (vData, vCounter + 10, cellHeight + auxPos.y);
SetData (vData, vCounter + 11, layer-> depth);

vCounter + = 12;

float textureWidth = tileset-> texture-> width,
textureHeight = tileset-> texture-> height;

float rightCell = cell.right / textureWidth,
leftCell = cell.left / textureWidth,
topCell = cell.top / textureHeight,
bottomCell = cell.bottom / textureHeight;

SetData (uData, uCounter, leftCell);
SetData (uData, uCounter + 1, bottomCell);

SetData (uData, uCounter + 2, rightCell);
SetData (uData, uCounter + 3, bottomCell);

SetData (uData, uCounter + 4, rightCell);
SetData (uData, uCounter + 5, topCell);

SetData (uData, uCounter + 6, leftCell);
SetData (uData, uCounter + 7, topCell);

uCounter + = 8;

uSetData (iData, iCounter, 0 + iCounter);
uSetData (iData, iCounter + 1, 1 + iCounter);
uSetData (iData, iCounter + 2, 2 + iCounter);
uSetData (iData, iCounter + 3, 0 + iCounter);
uSetData (iData, iCounter + 4, 2 + iCounter);
uSetData (iData, iCounter + 5, 3 + iCounter);

iCounter + = 6;

for (int i = 0; i < 16; i++)
                    SetData(cData, cCounter + i, 1.0f);

                cCounter += 16;
            }
        }
    }

    layer->mesh = Mesh_Create (vData, vDataCounter, iData, iDataCounter, uData, uDataCounter, cData, cDataCounter);

free (vData);
free (uData);
free (iData);
free (cData);
}

This is how the mesh is created and drawn:

struct Mesh * Mesh_Create (GLfloat vertices[], unsigned int vertexElements, GLuint indexes[], unsigned int indexElements, GLfloat uvs[], without signature int uvElements, GLfloat colors[], unsigned int colorElements)
{
struct Mesh * mesh = (struct Mesh *) malloc (sizeof (struct Mesh));

mesh-> vertices = (GLfloat *) malloc (sizeof (GLfloat) * vertexElements);
memcpy (mesh-> vertices, vertices, sizeof (GLfloat) * vertexElements);

mesh-> uvs = (GLfloat *) malloc (sizeof (GLfloat) * uvElements);
memcpy (mesh-> uvs, uvs, sizeof (GLfloat) * uvElements);

mesh-> indices = (GLuint *) malloc (sizeof (GLuint) * indexElements);
memcpy (mesh-> indexes, indices, sizeof (GLuint) * indexElements);

mesh-> colors = (GLfloat *) malloc (sizeof (GLfloat) * colorElements);
memcpy (mesh-> colors, colors, sizeof (GLfloat) * colorElements);

// mesh-> elementCount = vertexElements * 3;
mesh-> elementCount = indexElements;

glGenVertexArrays (1, & mesh-> vao);
glBindVertexArray (mesh-> vao);

glGenBuffers (1, & mesh-> vbo[VERTEXBUFFER]);
glBindBuffer (GL_ARRAY_BUFFER, mesh-> vbo[VERTEXBUFFER]);
glBufferData (GL_ARRAY_BUFFER, sizeof (GLfloat) * vertexElements, & mesh-> vertices[0], GL_STATIC_DRAW);
glVertexAttribPointer (0, 3, GL_FLOAT, FALSE, 0, NULL);
glEnableVertexAttribArray (0);

glGenBuffers (1, & mesh-> vbo[TEXTUREBUFFER]);
glBindBuffer (GL_ARRAY_BUFFER, mesh-> vbo[TEXTUREBUFFER]);
glBufferData (GL_ARRAY_BUFFER, sizeof (GLfloat) * uvElements, & mesh-> uvs[0], GL_STATIC_DRAW);
glVertexAttribPointer (1, 2, GL_FLOAT, FALSE, 0, NULL);
glEnableVertexAttribArray (1);

glGenBuffers (1, & mesh-> vbo[INDICESBUFFER]);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, mesh-> vbo[INDICESBUFFER]);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (GLuint) * indexElements, & mesh-> indices[0], GL_STATIC_DRAW);

glGenBuffers (1, & mesh-> vbo[COLORSBFFER]);
glBindBuffer (GL_ARRAY_BUFFER, mesh-> vbo[COLORSBFFER]);
glBufferData (GL_ARRAY_BUFFER, sizeof (GLfloat) * colorElements, & mesh-> colors[0], GL_STATIC_DRAW);
glVertexAttribPointer (2, 4, GL_FLOAT, FALSE, 0, NULL);
glEnableVertexAttribArray (2);

return mesh
}

void Mesh_Render (struct Mesh * mesh)
{
glBindVertexArray (mesh-> vao);
glDrawElements (GL_TRIANGLES, mesh-> elementCount, GL_UNSIGNED_INT, NULL);
}

Can you say something wrong?

It seems that the strange tiles are deforming … Take a look:

X spacing