• Advertisement
Sign in to follow this  

fixed.

This topic is 4931 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

Ok. I get an access violation when I execute this code. My program is this in essance. while(true){ bad_function(); otherStuff(); } The 2nd time I call bad_function I get an access violation. I know I'm doing something wrong with new, and release, and ...
D3DXVECTOR3 *min=new D3DXVECTOR3();
D3DXVECTOR3 *max=new D3DXVECTOR3();
D3DXVECTOR3 *vCent=new D3DXVECTOR3();

min->x=NULL;
min->y=NULL;
min->z=NULL;
max->x=NULL;
max->y=NULL;
max->z=NULL;
vCent->x=NULL;
vCent->y=NULL;
vCent->z=NULL;






	ID3DXMesh *mesh;
	mesh=NULL;



    HDC hdc = CreateCompatibleDC( NULL );

    // Use the font I just made and save the old one.
    HFONT hFontOld = (HFONT)SelectObject(hdc, dx->font); 

char newText[MAX_TALK_LENGTH];
for (int qwert=0;qwert<MAX_TALK_LENGTH;qwert++){
	if (qwert<pPlayerInfo->atChar){
	newText[qwert]=pPlayerInfo->message[qwert];
	}
	else{
	newText[qwert]=NULL;
	}
}
		HRESULT hr=D3DXCreateText(dx->g_pd3dDevice,  //Device
                     hdc,          //GDI Device Context
                     newText, //Text 
                     0.001f,        //Maximum chordal deviation from true font outlines       
                     0.01f,          //Extrusion depth (along -Z axis)
                     &mesh,         //Mesh
                     NULL,          //Adjacency information
                     NULL);         //GlyphMetrics
			
    SelectObject(hdc, hFontOld);

    //DeleteObject( hFont );
    DeleteDC( hdc );


	
	
	
	



	BYTE *ptr=NULL;

	// get the face count
	DWORD numVerts=mesh->GetNumVertices();

	// get the FVF flags
	DWORD fvf=mesh->GetFVF();  // See DX9 Version

	// lock the vertex buffer
	hr=mesh->LockVertexBuffer(0,&ptr);





	hr=D3DXComputeBoundingBox((D3DXVECTOR3 *) ptr,numVerts,fvf,min,max);

	// unlock the vertex buffer
	hr=mesh->UnlockVertexBuffer();


vCent->x=(max->x-min->x)*0.5f;
vCent->y=0;
vCent->z=(max->z-min->z)*0.5f;

pPlayerInfo->mesh=mesh;
pPlayerInfo->vCent=vCent;




I'm sorry it is so long, but I would appreciate it if you take a look through it, I'm sure its something stupid. (I'm not sure, it might be when I make 'new' D3DXVECTOR3 objects..) Most of it is directX, but I'm sure my problem lies somewhere with the variables, and I still am quite a new programmer, so I figured it would be best to post it here in the beginner forums. I'm also sorry about the formatting, I'll fix that later... It shouldn't be too hard to follow. Thanks for your help, Adam [Edited by - Adams555 on October 25, 2004 7:48:49 AM]

Share this post


Link to post
Share on other sites
Advertisement
Adams555,

Typically "Access Violations" are caused whenever you try and read or write to an area of memory which you do not "own." The best way to find the problem is to set a breakpoint in the code and step through it.

Look for any uses of "->" and check that the pointer has been correctly initialized before being used.

Also, if you're assigning to a variable (array) that has been dynamically allocated, make sure that the element you're trying to assign to is within the boundry of your allocation.

I do not think your problem is with your vector memory allocations, but rather with one of your other variables which you do not show the decleration for. Possible candidates are: dx or pPlayerInfo.

Hope this helps.

[EDIT]:
I didn't scroll all the way down. mesh is supposed to be initialized in your call to D3DCreateText, but you never check to make sure the call succeeded. If the call fails, mesh will be NULL, in which case your calls to GetNumVertices() and GetFVF, etc... will all be invalid calls and could cause the behavior you're getting. Check the HRESULT to make sure it's S_OK.

Share this post


Link to post
Share on other sites
Quote:
Original post by jwalsh
joanusdmentia,

Perhaps I missed something. Didn't I mention the D3DCreateText?


Perhaps he started his reply before you posted your edit?

Share this post


Link to post
Share on other sites
Yeah, I hit reply and then realized I hadn't scrolled down either, so sat there going through his code while on the 'post reply' page. , so I didn't see your post until afterwards.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement