Skip to main content
GameDev.net gamedev.net
🔒 Locked

I don't understand the difference

Started by egwenejs Jun 18, 2010 at 5:44 AM 2 replies 1.3k views
Original Post
egwenejs
egwenejs
I'm using SlimDX for my Direct3D9 app. I found something I don't quite understand the reasons why it happens this way and I was hoping someone could explain it to me.

//The one that worksSurface oldRenderTarget = device.GetRenderTarget(0);device.SetRenderTarget(0, currScreen.RenderingSurface);device.Clear(ClearFlags.Target, currScreen.BackgroundColor, 1.0f, 0);device.BeginScene();spriteBatch.Begin();currScreen.Draw(spriteBatch);spriteBatch.End();device.EndScene();device.SetRenderTarget(0, oldRenderTarget);oldRenderTarget.Dispose();


Where currScreen is where I encapsulate the drawing and updating for what I want to show on the screen and spriteBatch is a pretty thin wrapper for SlimDX.Direct3D9.Sprite and device is an instance of SlimDX.Direct3D9.Device

//The one that doesn't workdevice.SetRenderTarget(0, currScreen.RenderingSurface);device.Clear(ClearFlags.Target, currScreen.BackgroundColor, 1.0f, 0);device.BeginScene();spriteBatch.Begin();currScreen.Draw(spriteBatch);spriteBatch.End();device.EndScene();device.SetRenderTarget(0, device.GetBackBuffer(0, 0));


So the second one draws correctly but when the device is reset it complains that all associated resources weren't released. But no other resources are being used but the dynamic texture and the sprite object which are definately being released beforehand. What's causing the problem?

In the first one which works and there are no complaints on reset. The object in the oldRenderTarget is the back buffer. BUT, I dispose of it. Shouldn't that cause a problem? It doesn't. Why not?
egwenejs
egwenejs
So, is my question poorly phrased?
egwenejs
egwenejs
Quote:

did you release oldsurface?


What do you mean oldsurface? Do you mean oldRenderTarget? I believe I call oldRenderTarget.Dispose() -- so the answer would be yes.

Quote:

what resources have been allocated

The ones shown - SlimDX.Direct3D9.Device, SlimDX.Direct3D9.Sprite, SlimDX.Direct3D9.Surface for oldRenderTarget, my screen class which wraps a dynamic texture. I think i said that in the original post.

Quote:

is that the exact code that is in winmain and nothing else


Well I said the code snippets in the original post draw to the screen correctly but the code shown causes a failure when the device resets. So, how could you assume that the code shown is all there is to the program?

Quote:

The information you give is very vague.


Really? What's vague about it. The 3 complaints you had about it were all due to not reading through the post and just looking at the code. If you really need more information what information do you need? The way to me clarify my own vagueness is not by being vague yourself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.