Sign in to follow this  
dave

memcpy() (I Think) Problem

Recommended Posts

Sorry guys, i hate to keep nagging you for help but im moving forward with my project quite rapidly and keep finding problems that i can never find documentation on. So here goes... I have written a wrapper for a vertex buffer and it has a pair of write functions that look like this... A write function for writing a single vertex to the buffer...
	template<class T>
	void Component_VB<T>::Write(T& v)
	{
		if (numberWritten < size)
		{
			void* a;
			pV = NULL;
			// lock the buffer
			Lock(v, (numberWritten * sizeof(v)) );

			a = memcpy(pV, &v, sizeof(v));

			Unlock();

			if (a != NULL)
			{
				numberWritten++;
			}
			else
			{
				assert(0);
			}
		}
		else
		{
			assert(0);
		}
	}


A write function for writing an array of vertices to the buffer...
	template<class T>
	void Component_VB<T>::Write(T v[], unsigned int qty)
	{
		if (numberWritten < size)
		{
			T tempVerts[1000]; // <<Used for simple test code

			VOID* a;
			VOID* vPointer;

			vertexBuffer->Lock(0, (qty *sizeof(T)),(void**) &vPointer, 0);

			a = memcpy(&tempVerts[0], &v[0], qty*sizeof(T));

			a = memcpy(vPointer, &v[0], qty*sizeof(T));


			vertexBuffer->Unlock();

			if (a != NULL)
			{
				numberWritten++;
			}
			else
			{
				assert(0);
			}
		}
		else
		{
			assert(0);
		}
	}


The first one works fine by moving through the array by one vertex every time the function is called. Now this is the function that i am currently using. This function obviously is slow to use because of the Lock() Unlock() which would be called thousands of times. I want to implement the second function which takes a pointer to an array of vertices and the number to be copied. As a test to see if i was recieving the vertices through the parameter as i wanted i added an internal array to also copy to, using the top memcpy(). Then second memcpy() is to copy to the void* pointing to the VB. Now the vertices do copy correctly from the the parameter to the internal array but they obviously dont copy to the VB correctly since the on-screen object doesnt render. The on screen object does render if they are written one at a time. Also i should add that the Lock function is wrappedVB function that does work for simply usage. In the second function i havnt used it. So if you can take that function for granted in the first example. Can anyone see why this might be the case? I have tried alot of different syntax's to try and solve this but non have worked obviously. Sorry to take up more of your time, ace

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
Yes vPointer does recieve a valid address.
Quote:
Original post by Oluseyi
Have you single-stepped through the code?
This second part can give you insight into what's wrong, though I'll be the first to admit that debugging Direct3D is challenging. You very often need a multimon setup to do it effectively.

Try using trace statements to see what's up.

Share this post


Link to post
Share on other sites
Yes it is dynamic, but the setup o teh VB is fine because i have used it when writing 1 vertex to the VB at a time, so it isnt that. All return codes are correct when stepping through. I guess i could try looking at the memory as it is written but i wouldn't really know what to look for.

Any further ideas?

ace

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this