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

MDX/C# Struggling to understand problem..

Started by Michael Tanczos Jun 16, 2009 at 7:51 AM 6 replies 3k views
Original Post
Michael Tanczos
Michael Tanczos
I'm struggling to understand what I'm missing, and perhaps someone here knows something high-level that I'm not thinking of. In short, my live video that I'm capturing through directshow displays for about 10 seconds in a picture control and then goes black. To boil down the problem, I'm passing a valid direct3D surface that contains a frame of live video from a camera to a rendering function. I "convert" the surface into a texture when passing to the rendering function first. Just to make sure the surface and texture contains valid image data I tried periodically saving the surfaces to disk and they do indeed contain correct video frames. So the problem I'm having is that I'm setting my rendertarget to an image control inside a form, and my basic test rendering loop code looks like this:

// spr is just a D3DX sprite

d3dDev.SetRenderTarget(0, renderTarget);  // renderTarget is a surface that references the original render target when the device was created
Vector3 ctr = new Vector3(0, 0, 0);

d3dDev.Clear(ClearFlags.Target, 0x00000000, 1.0f, 0);
d3dDev.BeginScene();

spr.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortDepthFrontToBack);
spr.Draw(texture, System.Drawing.Rectangle.Empty, ctr, ctr, System.Drawing.Color.White);
spr.Draw(img, System.Drawing.Rectangle.Empty, ctr, ctr, System.Drawing.Color.White);
spr.End();

d3dDev.EndScene();
d3dDev.Display();


.. the correct image stops displaying inside the image (picture) control after about 10 seconds and instead the only thing that seems to work is the d3dDev.Clear call, which does clear the surface. The odd thing is that it works perfectly fine on my home computer, but not on my work computer. Any ideas? Thanks in advance. - Michael Tanczos
Adam_42
Adam_42
Have you tried either using the debug DirectX runtimes, or just checking the error codes to see which calls (if any) are failing?

There's also a chance you're running out of some kind of resource. Double check that everything is disposed of properly.

What's the difference between the two computers?
Michael Tanczos
Michael Tanczos
Right now I don't see any errors being generated but I'll double check. As an odd comment, the more times I call spr.Draw within that loop, the faster the window output goes to black. Just for kicks, I made about 15 spr.draw calls within that loop and the time to go to black went from about 10 seconds to a second or two. The two computers are pretty similar..

- Michael Tanczos
feal87
feal87
With this little data I can't tell you much. Post a Zip with the executable and a test data so i can test it with Pix and tell you exactly what's happening.
sirob
sirob
Sounds like a leak of GPU resources of some kind, eventually resulting in an error due to lack of memory of some kind.
Are you verifying all results for resource creation?
Maybe you forgot a dispose somewhere?
Are you even creating any resources per-frame?
Sirob Yes.» - status: Work-O-Rama.
Michael Tanczos
Michael Tanczos
I'm not creating any new textures or allocating anything new, as far as I know. In C# I am not passing the textures by reference.. The problem seems entirely related to using D3DX sprites.. if I render the video frame out to a textured quad it works indefinitely without any problem. I'm just not sure how these sprites can fail to draw a valid texture to the screen after a few seconds. It does seem like it should be a resource leak.. but there is an interesting twist. If I wait long enough, the frames will draw correctly again for about 10 seconds and then go black again for a while.

- Michael Tanczos
Michael Tanczos
Michael Tanczos
One more followup.. If I recreate the sprite on each frame I draw and then destroy it at the end of the frame render, my program works fine. So perhaps something is happening to the sprite itself..

- Michael Tanczos
Mike.Popoloski
Mike.Popoloski
Are you handling device lost / device reset properly? I know he D3DX Sprite interface needs you to notify it when these happen so that it can clean up / recreate things internally.
Mike Popoloski | Journal | SlimDX

Topic Locked

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

Sign in to reply to this topic.