Vicente Cartas

Hi,

IĄŻm the coordinator of Jad Engine, a MDX 1.1 open source 3d engine. We have had one bug around for several months that we are unable to solve related to resizing the device.

At the start, we used SetAutoDepthStencil = true when creating the device, and there was nor problems with the resize. But nowadays we do it manually and SetAutoDepthStencil is false.

But when we reset the device, the D3D debug tells us that one surface has not being liberated. That surface is the DepthStencil we just created, because if we donĄŻt create it, the reset works.

The Microsoft.DirectX.Direct3D.Device.IsUsingEventHandlers is set to false as we create ourselves the VertexBuffers in DEFAULT mode and thatĄŻs the only way that they donĄŻt give us an error on the reset.

We would be really glad if someone could help us here, this nasty bug is slowing a lot our work in the editor part of the engine, and we are unable to track it :(

Regards,

Vicente


Re: Game Technologies: General Problems on resize

Inaki Ayucar

Hola Vicente ! como estas

IĄŻll write in english so everybody can understand.

IĄŻve been looking around your resizing problem. You probably already knew this, but "por si acaso"

Setting EnableAutoDepthStencil to false will force you to manage the DepthStencilSurface manually. That means that you have to disable it manually in the OnLostDevice event and re-create it again in the OnResetDevice. In fact, the best is to create it in the OnReset only, once the device is properly created.

If you dont explicitly call the DepthSurface.Dispose(), the Reset will always fail.

Hope this helped.

Saludos !

Inaki Ayucar






Re: Game Technologies: General Problems on resize

Inaki Ayucar

Sorry, when I said "you have to disable it manually" I meant "you have to dispose it manually"...






Re: Game Technologies: General Problems on resize

Vicente Cartas

Hola Inaki!

thks for your answer, IĄŻll pass it to the guy who is on the graphics part (I do the AI part) to see if it helps him to solve this dammed bug.

IĄŻll tell you what happens. Regards!

Vicente




Re: Game Technologies: General Problems on resize

Inaki Ayucar

Hi again. Ok Let me know if you need anything else.

Anyway, reading what I posted yesterday, I noticed that I was not very clear. It was late... you know...

What I meant is that you have to deal with the DepthSurface the same way you deal with any other DefaultPool resources (textures, vertexbuffers, whatever...).

This resources do not survive to a Device state transition. So, If the device is lost (like in a resize operation), they should be all Disposed in the OnLostDevice in order the Reset to work properly, and re-created in the OnReset (after reset, once a valid device is available again) to get all of them again into video memory.

Only ManagedPool resources can live through device state transitions. If you plan to put your resources in DefaultPool, as I do, the best is to create a ResourceManager that handles all this stuff. ThereĄŻs an example of this kind of manager in the Microsoft.Samples.DirectX.UtilityToolKit. Although that one wonĄŻt probably cover all your needs, you can use it as a basement.

ItĄŻs also a good Idea to create one of this managers for each kind of memory pool you need in your application or game. For example, itĄŻs usual to have separate managers for:

* Global resources: created at start up. Common textures, etc

* Scene resources: created on scene load. Objects, textures, etc

All of them have to be disposed-created in a state transition, but when the player gets off a mission or scene, only scene resources are disposed.

I can show you how IĄŻm doing it in the simulator project David Carmona told you.

Hope this helps

Best regards,

Inaki.






Re: Game Technologies: General Problems on resize

Inaki Ayucar

Hi there again, I think I found the problem. Let me know if it still doesnĄŻt work...
In order to get no exceptions when resetting the device, due to a resize or to a FullScreen toggle, you must be sure to have freed every single resource of the device, because for each resource, DirectX mantains an internal counter of references. If any of these counters is not 0 at Reset, it throws an exception and the Reset fails.
Well, in order to make sure this counters are all 0:
1.- Every resource must be Disposed in the OnLostDevice() event.
2.- Every resource must be re-created in the OnResetDevice() event.
BUT: thereĄŻs a singularity to this procedure regarding the DepthStencilBuffers.
If you handle depth buffers manually (setting the EnableAutoDepthStencil = false), thereĄŻs something you have to be careful with.
When an access to the Device.DepthStencilSurface is done, the API actually calls to the native Device->GetStencilSurface() method. If you take a look at the GetStencilSurface() specs in the SDK C++ docs, you will find that this method increments the resourceĄŻs internal reference counter. So:
AFTER TO EVERY SINGLE ACCESS TO Device.DepthStencilSurface, YOU MUST DECREMENT THE REFERENCE COUNTER
If you donĄŻt, you will get an exception at Reset. How to decrement the counter Calling the Dispose() method.
Example:
1.- ACCESS
Surface mySurface = null;
try
{
mySurface = device.DepthStencilSurface;
}
catch {}
........... [ DO YOUR STUFF HERE ] ..................
2.- RELEASE
if(mySurface != null)
{
mySurface.Dispose();
}





Re: Game Technologies: General Problems on resize

Vicente Cartas

Man, thks a lot for the elaborated answer :) IĄŻll tell the other people of the team and check this one :)

Regards!

Vicente




Re: Game Technologies: General Problems on resize

Inaki Ayucar

YouĄŻre welcome !!!

Let me know if that fixed the problem.