Memcpy(); Errors...

This is a discussion on Memcpy(); Errors... within the C++ Programming forums, part of the General Programming Boards category; I'll just start off with the code.. Code: int nVertices = *( word* )pPtr; NumVertices = nVertices; Vertices = new ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Memcpy(); Errors...

    I'll just start off with the code..

    Code:
    	int nVertices = *( word* )pPtr; 
    	NumVertices = nVertices;
    	Vertices = new Vertex[nVertices];
    	pPtr += sizeof( word );
    
    	int i;
    	for ( i = 0; i < nVertices; i++ )
    	{
    		MS3DVertex * pVertex = ( MS3DVertex* )pPtr;
    	//	Vertices[i].BoneID = pVertex->m_boneID;
    		memcpy( Vertices[i].vx, pVertex->m_vertex[0], sizeof(float));
    		memcpy( Vertices[i].vy, pVertex->m_vertex[1], sizeof(float));
    		memcpy( Vertices[i].vz, pVertex->m_vertex[2], sizeof(float));
    		pPtr += sizeof( MS3DVertex );
    	}
    Okay, so I'm copying pVertex->m_vertex elements to each element in my structure in code, I'll show you the definitions of each of these structs..

    I'm copying from this one

    Code:
    // Vertex information
    struct MS3DVertex
    {
    	byte m_flags;
    	float m_vertex[3];
    	char m_boneID;
    	byte m_refCount;
    } PACK_STRUCT;
    To this one
    Code:
    	struct Vertex
    	{
    		float vx;
    		float vy;
    		float vz;
    		float nx;
    		float ny;
    		float nz;
    		float s;
    		float t;
    		unsigned char r,g,b,a;
    	};
    
    	int NumVertices;
    	Vertex * Vertices;
    That is all I'm doing, maybe I'm not using memcpy right?

    Here are the errors..

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    MS3D.CPP
    \\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(192) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
            There is no context in which this conversion is possible
    \\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(193) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
            There is no context in which this conversion is possible
    \\student\courses\cedar_cliff\computer\senior project\auditorium\engine source\ms3d.cpp(194) : error C2664: 'memcpy' : cannot convert parameter 1 from 'float' to 'void *'
            There is no context in which this conversion is possible
    Any ideas?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    How about just doing an assignment like any normal person would?
    Vertices[i].vx = pVertex->m_vertex[0];

    Of course it doesn't work, you forgot a whole bunch of & to turn things into addresses.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    For some reason this works though...

    Code:
    	int nTriangles = *( word* )pPtr;
    	NumTriangles = nTriangles;
    	Triangles = new Triangle[nTriangles];
    	pPtr += sizeof( word );
    
    	for ( i = 0; i < nTriangles; i++ )
    	{
    		MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
    		int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
    		float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
    		memcpy( Triangles[i].VertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
    		memcpy( Triangles[i].Textures1, pTriangle->m_s, sizeof( float )*3 );
    		memcpy( Triangles[i].Textures2, t, sizeof( float )*3 );
    		memcpy( Triangles[i].VertexIndices, vertexIndices, sizeof( int )*3 );
    		pPtr += sizeof( MS3DTriangle );
    	}
    Why's this work and that doesn't?

    Strange...

    I'll go ahead and use an assignment operator, but it is really strange why the code above works but the origional code in the op doesn't :\...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > memcpy( Triangles[i].Textures1, pTriangle->m_s, sizeof( float )*3 );
    Probably because these are all ARRAYS, and hence become pointers to the first element of the array in this context.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Hm, I see..
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. memcpy with 128 bit registers
    By grady in forum Linux Programming
    Replies: 2
    Last Post: 01-19-2004, 05:25 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21