Sign in to follow this  

How do I delete objects?

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

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 this post


Link to post
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 this post


Link to post
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[i] );

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferWidth = 600;

there's my problem. It must be 600 and 800, not 600 and 600. But...why? 800x600 stretches out the objects. If I load in a perfectly circular sphere .x file, it looks squished, so I fixed that with a 600x600 res. But it doesn't like that at fullscreen?

Share this post


Link to post
Share on other sites
uhm, I assume you should just use a resolution that the graphics card and your monitor support, which are either 4:3, 16:9 or 16:10 aspect ratio resolutions. Common resolution are:
- 800 x 600
- 1024 x 768
- 1280 x 960
- 1600 x 1200
- 1600 x 900 (16:9 aspect ratio)
- 1680 x 1050 (16:10 aspect ratio)

As for the "jerky" rotation:
On my PC those two objects are rotating rather nicely, although the app is running only at ~35 FPS. The only thing jerky I noticed was some small "stutters" in the rotation when the FPS dropped a bit.

Share this post


Link to post
Share on other sites
In windowed modes you can have whatever resolution you desire. When in fullscreen mode, you are changing the resolution of the screen/graphics card. There are only a certain number of combinations that the card will accept, and they are usually in set ratios (either 4:3 for standard views or 16:9 for widescreens).

If your model is getting squished when you set it to 800x600 then you are not setting up your frustrum correctly.

Share this post


Link to post
Share on other sites
Ok thanks guys. As for the rotation, I tried it on my other computer and it does seem a lot smoother. The only problem is that it doesn't load the texture files o_O' It says it can't find them, but they're clearly right there. Weird. That computer does have DX9.0c, so that shouldn't be a problem. Ugh, so many hoops to jump through with this thing.

Share this post


Link to post
Share on other sites
Having a look at the the .x files of your meshes it seems the texture file names are given in absolute paths, for example your myball.x contains the following:

TextureFilename {
"C:/i345/C++/thegame/Debug/myobject2.bmp";
}

which indicates the texture should be at that exact location. Probably your other mesh file has the same "problem". However I have no idea how to change that in an automated way, since I never used the texture file names stored in the .x files but loaded textures directly. Changing the above line to "myobject2.bmp" fixes the problem for that specific file.

Share this post


Link to post
Share on other sites
holy crap, I never would have guessed that. My gosh. Thank you so much. I'm so glad it's a simple fix instead of a DirectX version or a programming problem!

Now if I could only figure out why the application runs so slow on my computer... I have a GeForce 5500. It shouldn't have such a slow frame rate.

Share this post


Link to post
Share on other sites
Ok, I'm trying to translate on of the objects now. I figured, I should use this:


D3DXMATRIX *WINAPI D3DXMatrixTranslation( D3DXMATRIX *pOut,
FLOAT x,
FLOAT y,
FLOAT z
);



however, the compiler doesn't like it. I'm guessing because "D3DXMATRIX *pOut" is something I don't have. I think that needs to point to a D3DXMATRIX thing, but I haven't made any of my meshes a D3DXMATRIX thing. I tried putting in m_pMesh[1] to target the myball.x mesh, but that doesn't work. I did it like this: D3DXMATRIX *m_pMesh[1],

So it appears as though I need to somehow make myball.x a D3DXMATRIX thing after I load it in with D3DXLoadMeshFromX. How do I do this?

Share this post


Link to post
Share on other sites
I just had another look over your code and it seems that you are using software vertex processing, which means that all vertex transformations are done by the CPU, and not your graphics card. You probably will want to try D3DCREATE_HARDWARE_VERTEXPROCESSING instead of D3DCREATE_SOFTWARE_VERTEXPROCESSING in the call to CreateDevice(...) in your initDirect3D(...) function. That should speed up your application quite a lot, I hope. Furthermore you could try D3DXMESH_MANAGED instead of D3DXMESH_SYSTEMMEM when loading the meshes. Using the managed pool for the data will allow Direct3D to copy the data to the video memory if possible / necessary, which should also aid performance.

Share this post


Link to post
Share on other sites
I really think you should have a look at some Direct3D tutorials for beginners. Have a look at the DirectX forum FAQ in this forum and you´ll find a list of tutorial sites under "Web Resources". After following some of these tutorials you should be able to do most "easy" things on your own.

Share this post


Link to post
Share on other sites
ahh yes well, I actually did try the hardware thing, but that didn't help at all, so I switched it back. Trying hardware with D3DXMESH_MANAGED also doesn't speed it up at all unfortunately.

I'll take a look at some of those tutorials you mentioned.

Share this post


Link to post
Share on other sites

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

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