glFlushMappedBufferRange and GL_INVALID_VALUE

Hi!
I'd like to upload a bunch of vertices of meshes (simple arrays of float values x,y,z) into a single vbo. I've created a unique buffer with the total ammount of bytes needed to contains all the vertices

then reading each mesh vertices array i'd like to copy those bytes into the buffer, each at the right offset inside the VBO. to do that i calculate the offset and size of each array to copy then i call a function that simply do this

offset is 0 at the begin, size is the size of the array in bytes, then the next mesh offset+= size, size = new_mesh_size. The problem is that at the second mesh copy, when i flush the data, OpenGL gives me a GL_INVALID_VALUE error. I checked all the ranges values and everything is ok (the buffer is like 2 Mbytes and the first mesh is like 3000 vertices, the second 1000) and if the ranges are wrong i'd assume glMapBufferRange would give me an error first, isn't it?

If i remove the flush and let it do the operation automatically with glUnmapBuffer there's no error. Any ideas why i cannot flush the second slice?