# How do I delete objects?

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

## Recommended Posts

This is my code: http://www.philosophyzero.com/code.txt It's very basic. It loads in a .x mesh, slaps textures on it, etc. To delete the object, you press the d key. That calls DestroyGeometry(). But I get a memory error. What's wrong? And on a side note, why is the rotation of the object so jerky? SetupMatrices() does the rotation like this: D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f ); Lastly, do I have to do something with classes to make the .x mesh an object? Like OOP? Because I think that's rotating the world instead of the actual .x object.

##### Share on other sites
when it breaks in the debugger, what line is giving you the error?

-me

##### Share on other sites
Ok, after it executes this line:

m_pMesh->Release();

in the deleteGeometry function, it gives me the error.

which is line 425, all the way at the bottom

##### Share on other sites
Assuming that's all your code, you never initialize m_pMesh to NULL nor do you set it to anything valid anywhere. it's just pointing to random memory.

-me

##### Share on other sites
I might be completely off, but perhaps this could be the reason:
I suspect that your keypress on 'd' is processed more than once and because you´re never setting m_pMesh to NULL your if(...) for the Release is pointless. If that is the reason you can simply fix it by changing:
if( x != NULL){    x->Release();    x = NULL;}

you should do that for every resource you release anyway. AFAIK many people have a SAFE_RELEASE macro for that, which calls Release if the supplied pointer is not NULL and sets the pointer to NULL afterwards.

##### Share on other sites
Hmmm. I set it to NULL after I delete it, but it seems to still be generating an error. Perhaps I'm reading the debugger incorrectly. It jumps to this line:

pd3dDevice->SetMaterial( &m_pMeshMaterials );

in render() directly after I get the error. Does that mean the error happens on that line or the previous line? Because I thought it meant the error was on the previous line, but maybe I'm wrong and it's actually refering to the line I wrote above. It puts a green triangle to the right of the code in VC++.

##### Share on other sites
I think I figured it out. The problem is that it's trying to render stuff that isn't there. I set up an if statement that controls the calling of the render function. If I don't render after I delete the objects, I don't get an error.

Now that that's solved, is there a way to rotate the actual object? Because I think I'm rotating the camera and not the actual object. And I'm still wondering why the rotation is still so jerky. I've messed around with the speed of the rotation, but it's always jerky no matter what I do.

##### Share on other sites
I think you´re refering to this part of your code from SetupMatrices():
D3DXMATRIXA16 matWorld;D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

The world matrix transforms the object from object space (the space it was modelled and stored in) to world space. So, essentially it moves, rotates, scales, whatever the object. What "moves" the camera is the view-matrix. If you´re interested to know more of that stuff you should look at the Direct3D Transformation Pipeline article in the DirectX SDK documentation.
As to why your rotation is jerky, I don´t have an idea, sry. As far as I can see, the object should rotate at 1 rad per second around the Y-axis.

##### Share on other sites

Well here's the .exe, the C++ file if you want to compile it yourself, the two .x files, and the two textures that go with them:
http://www.philosophyzero.com/Release.rar

If anyone would be kind enough to help me figure out why the rotation is so jerky, I would really appreciate it. Another problem that seems to have come up is that I can't put it into fullscreen anymore. This is really odd because I didn't change any of the fullscreen code. The debugger says

wndHandle = CreateWindow(			// create the window		"DirectXExample",			// window class to use		"DirectXExample",			// title bar text		m_dwWindowStyle,			// m_dwWindowStyle is the variable from IF statement above		CW_USEDEFAULT,			// the starting x coordinate for the window		CW_USEDEFAULT,			// the starting y coordinate for the window		800,					// window width size		600,					// window height size		NULL,					// parent window (NULL for desktop)		NULL,					// the menu for the application (NULL for none)		hInstance,				// the handle to the application instance		NULL);					// no values passed to the window

is an invalid line of code for some reason. I don't understand why... it's perfectly correct. It skips right over all that code even if I don't try to do fullscreen. The funny thing is that it still displays the correct window title when the window is created: "DirectXexample". So maybe it is running through the code? I'm confused now.

##### Share on other sites
ahh I found the problem. It's not wit hthe window creation after all. It's with this code:

	if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wndHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) )	{		return false;					// but if it fails to be created, return false to quit application	}

it fails.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632590
• Total Posts
3007249

×