Error w/ HLSL .fx Shader on Device.Lost

Hey guys,
     I am an indi. developer and I am working on a big project that needs some assistance. I have tested my application that I have built and the engine I am writing for it and came across a nasty error. My engine works off of different elements that are displayed in my SceneManager class... examples.... fxImage, fxText, fxFont to be rendered upon the screen. Right now I am trying to cover all the aspects of Device.Lost/Reset and memory management now before I continue to add more content. I have all my elements append an Event Handler of OnDeviceReset(...)/OnDeviceLost(...) to the Direct3D device.

By doing that it allows me to easily manage more effeciently having to reinit. resources unmanaged. When I do it with my shader element... it doesnt work. I tested my code out in Fullscreen mode and Alt-Tab'ed out and back into the program no problem when the SceneFX class wasnt included in my startup code which contains two Effect variables.

I have read that shaders in DX9 automatically are "remembered" by the device... if that is the case then why am I running into an error when I try to Alt-Tab, Ctrl-Esc, etc... (ie. Lost Device) out of my program with the shader included.

Here is my code for the lost/reset functions of my SceneFX element...


public void OnDeviceReset(object sender, EventArgs e)

{

if (!FXEngine.Instance._renderer.shutDownRenderer)

{

backBuffer = FXEngine.Instance._renderer.Device.GetRenderTarget(0);

backBufferCopy = new Surface(FXEngine.Instance._renderer.Device,

new System.Drawing.Bitmap(FXEngine.Instance._renderer.Resolution.resWidth,

FXEngine.Instance._renderer.Resolution.resHeight), Pool.SystemMemory);

texPixelShaderX = new Texture(FXEngine.Instance._renderer.Device,

FXEngine.Instance._renderer.Resolution.resWidth, FXEngine.Instance._renderer.Resolution.resHeight,

1, Usage.RenderTarget, FXEngine.Instance._renderer.Resolution.resFormat, Pool.Default);

surfPS = texPixelShaderX.GetSurfaceLevel(0);

scene = new Texture(FXEngine.Instance._renderer.Device,

FXEngine.Instance._renderer.Resolution.resWidth, FXEngine.Instance._renderer.Resolution.resHeight,

1, Usage.None, Format.A8R8G8B8, Pool.Default);

sceneRender = scene.GetSurfaceLevel(0);

FX_X.OnResetDevice(); <-Gaussian Blur Shader For X-Axis

FX_Y.OnResetDevice(); <-Y-axis

}

}

public void OnDeviceLost(object sender, EventArgs e)

{

if (!FXEngine.Instance._renderer.shutDownRenderer)

{

FX_X.OnLostDevice();

FX_Y.OnLostDevice();

if (!(backBuffer == null))

{

backBuffer.ReleaseGraphics();

backBuffer.Dispose();

backBuffer = null;

}

if (!(backBufferCopy == null))

{

backBufferCopy.ReleaseGraphics();

backBufferCopy.Dispose();

backBufferCopy = null;

}

if (!(texPixelShaderX == null))

{

texPixelShaderX.Dispose();

texPixelShaderX = null;

}

if (!(surfPS == null))

{

surfPS.ReleaseGraphics();

surfPS.Dispose();

surfPS = null;

}

if (!(scene == null))

{

scene.Dispose();

scene = null;

}

if (!(sceneRender == null))

{

sceneRender.ReleaseGraphics();

sceneRender.Dispose();

sceneRender = null;

}

}

}


 


Hope someone can help shed more light on my problem.. thanks guys for readin through all this ***...

[POST EDIT]

Okay... so I ran the debugger step by step... it does make it through successfully past the objects and unloads everything unmanaged in the scene. However, when it gets to the point where it says "there is no more code in this location"... it immediately shifts to my main forms disposing method. When I went through it with the object not included in the scene, instead of going to my main form... it went where it was supposed to and thats my Devices End Call when it uses try {} catch {} to get the LostException... I dont get it...

[POST EDIT]

I was able to isolate where it was coming from...

public void Render()

{

backBuffer = FXEngine.Instance._renderer.Device.GetRenderTarget(0);

//FXEngine.Instance._renderer.Device.GetRenderTargetData(backBuffer, backBufferCopy); <-This is the error creator

FXEngine.Instance._renderer.Device.UpdateSurface(backBufferCopy, sceneRender);

Matrix worldViewProj = Matrix.Identity;

worldViewProj.Multiply(FXEngine.Instance._renderer.World);

worldViewProj.Multiply(FXEngine.Instance._renderer.View);

worldViewProj.Multiply(FXEngine.Instance._renderer.Projection);

...

Okay so it occours when I make the device lost. It is fine up until then. I will let you understand why I am using that funtion... I have a Gaussian Blur PS2.0 shader that has a technique for the y axis and x axis. I need it to happen to the entire screen... so I try my best to create a texture of the backbuffer. I get the backbuffer... I update it onto a texture in System Memory so that I am able to use the device.updatesurface.... If someone knows why this is interfearing with my Device.Lost and another way around using that function.... thanks again guys

[POST EDIT]

Hey guys... got it all taken care of for now. I rendered all my data to a texture and used that texture as my shader tex. It allowed me not to use that funtion which doesnt create the error anymore. thanks anyways... lata....




Answer this question

Error w/ HLSL .fx Shader on Device.Lost

  • Roesel

    ok, we'll mark the thread as closed then Smile

  • Error w/ HLSL .fx Shader on Device.Lost