Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey!

 

I'm trying to learn d3d by developing this game (sidescroller, somewhat like shadow of the beast, if you remember). For the background I use tiles (3 rows as of now).

 

The problem: after I kill the app, the process is still alive.

I dipose my vertex buffers, but obviously I'm missing something.. Could anyone give me some pointers?

I should probably say that all objects are separated from the Form-class, and uses it to render themselves.

/h

Posted

Ok, what I do is this:

 

For each background (that is, a series of GameObjects = quads), calculate coordinates for the texture and:

private void setupBackground()
{
for(int i = 0; i<this.tiles.Length; i++)
{
	tiles[i] = new GameObject(this.device, (i * TILESIZE), this.yPosition, TILESIZE, TILESIZE);
	tiles[i].setTextureCoords(this.texCoords[i][0], this.texCoords[i][1], this.texCoords[i][2], this.texCoords[i][3]);
}
}

 

the cleanup i do for the background. Each tile (GameObject) disposes of its vertexBuffer:

public void cleanUp()
{
for(int i=0; i<tiles.Length; i++)
{
	tiles[i].cleanUp();
}
t.Dispose(); // texture
}

And finally, after calling cleanup for all backgrounds, the form-class calls dispose for the device.

 

Running, this app uses 25-30% CPU, and when shut-down it jumps to 99% and stays there until I kill it myself.

/h

Posted

Hmm ive done that before.

 

Are you sure youve created an exit condition for your main loop (or all loops for that matter) make sure to set running = false or what ever condition is needed to exit all loops before you call the end statement or whatever you quit with.

Posted

What I do is:

static void Main() 
{
rForm rf = new rForm();
//Init graphics
rf.initGFX();
rf.Show();

while(rf.Created)
{
	rf.Render();
	Application.DoEvents();
}
rf.cleanUp();
}

where rf is the form.

If I set some breakpoints and run with the debugger, it actually dies by itself, but it takes quite a while to get out of the while-loop for some reason. what render does here is call render for my background objects, who in turn lets the tiles render to the form..

for(int i=0; i<tiles.Length; i++)
{
tiles[i].Render();
}

..in the usual way (I guess)..

public void Render()
{
initObject();
device.VertexFormat=CustomVertex.TransformedTextured.Format;
device.SetStreamSource(0, vBuffer, 0);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
}

Is 'while(rf.Created)' my problem?

/h

Posted

It appears so

 

Im only a VB programmer so i dont really understand your code 100% but in my experiance id say you whould run the main loop on a boolean variable not a member of a class if you have an event like device.lostfocus that would cause it to quit the game or in your case form.exiting or whatever the appropriet event is add a sub to handle said event and just change the boolean to false then. Try it if it fails then hey ill admit im wrong.

Posted (edited)

I've tried using a boolean, too, responding to a key-event. It works while running it inside VS using the debugger, but not otherwise (same as with the form.Created condition).

After testing a bit by commenting out the rendering of two of my backgrounds and running only the third, it does shut down after about 10 sec. So am I doing this the wrong way, creating an object for each tile? They only contain a vertexBuffer, coordinates for the texture and their position, so..

/h

Edited by hsv
Posted

In My experiance

 

I have found that disposing of the DX objects does take 5-10 seconds when exiting an application, Less when compiled and even less when running with a release version of dx instead of a Debug version this time was much more apparent with DX8 in VB6 However it still seems to be there in VB.net and DX9.

Posted

I compiled in release mode , and ran it with the release version of dx. Five minutes after I shut it down, the process was still at 99% and I killed it. What I don't understand is why a third object of the same class can mess it up like this. There are 16 more tiles and a texture, thats all!

/h

Posted

After 5 Minutes

 

And assuming your processor speed can be measured in mega hertz without decimals im guessing that there is still a loop going somewhere in the program, DX simply has never been that long when disposing, even with my code and i assure you if any programmer is going to find a way to screw something up in the most idiodic fassion possible i would be supprised if it wasnt me. (note my programming is effectivly self taught outside a very basic course in vb6 "this is a form... This is a button, you can put a button on a form.,.. This is a message box... etc..."

Posted

Thanks for the interest, I got it working now..

You're not the only one who can screw up, trust me :)

I made a lot of changes, but I guess not disposing of the device before cleaning up the resources helped.

 

/h

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...