Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

supagu

vertex cache

This topic is 5641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to set up a vertex cache, i have a function
void StartCache()
{
	//lock buffers	
	if( FAILED( indexCache->Lock(0, 0, (void**)&index, 0) ))
	{
		systemLog.WriteLog("Lock Cache Index buffer [FAILED]");
		return;
	}
	
	if( FAILED( vertexCache->Lock(0, 0, (void**)&vertex, 0) ))
	{
		systemLog.WriteLog("Lock Cache Vertex buffer [FAILED]");
		return;
	}
}
 
which loks the buffers so i can write to them through out the scene, the problem is with the "index" and "vertex" variables which are defined as:
WORD* index;
STANDARD_VERTEX* vertex;
 
now when i use the sample code:
		index[ 0 ] = 0;
		index[ 1 ] = 1;
		index[ 2 ] = 2;

	STANDARD_VERTEX temp;
	temp.p = D3DXVECTOR3(0,0,0);

		vertex[ 0 ] = temp;
		vertex[ 1 ] = temp;
		vertex[ 2 ] = temp;
 
and i put that code after i lock the buffers (in the same function), then it works fine, but if i goto use that same peice of code any where else (before locking the buffers, and in the same file so they have access to "index" and "vertex", it causes my app to crash. any ideas on what is acuasing this?

Share this post


Link to post
Share on other sites
Advertisement
I have an idea (hopefully the right one).
When you are locking the vertex/index buffer, notice that you are sending a pointer to a pointer. This means that in the lock function the value of the pointer changes.
It changes to point on a region of memory which is validly allocated, whereas when you use that piece of code elsewhere, the two pointers point to garbage, probably causing an access violation.
I hope this helps

Share this post


Link to post
Share on other sites
Pointers obtained from Lock() calls aren''t guaranteed to be preserved after Unlock(). i.e. When you Unlock(), the pointers point to invalid memory.

Always Lock() to get your pointers, and when you Unlock(), set your pointers to NULL.

Peace,
Muhammad Haggag

Share this post


Link to post
Share on other sites
yeah thats the tut im reading,

i dont use the pointers i get when i lock after i unlock, i use them in between the lock and unlock only...

it seems to me something is funny like the variables are going out of scope at the end of the function call, but they shouldnt be because they are global
:-/

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!