Jump to content
  • Advertisement
Sign in to follow this  


This topic is 5109 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 ...


	ID3DXMesh *mesh;

    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){
		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=D3DXComputeBoundingBox((D3DXVECTOR3 *) ptr,numVerts,fvf,min,max);

	// unlock the vertex buffer



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

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.

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
Original post by jwalsh

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

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!