Hello,
I'm new to managed DirectX and have a great problem with memory leaks.
I think, its the best when I tell you something about the project and the
structure of the project.
The goal of the project is to render a scenegraph in a control ( I use a
panel as control, because I mentioned, that the picture box is buggy for
this).
Becuase there can be a lot of different objects I have written an own class
for rendering. The class is named RenderMain and is established in an own
assembly with other classes. This class has a property for the device and a
property for the control. The Mainform is established in an other assembly.
I'd overriden the OnPaint-Method of the Mainform like this:
The Methode m_RenderMain.PaintDevice() looks like this:
In the RenderScenegraph I render all items of the scenegraph. For this
purpose, every item of the scenegraph have a method which looks like thius:
The device is initialised in the following method of the RenderMain class.
All works fine and the graphical objects are rendered, but if I start the
taskmanager, I see, that the memory-use is increasing by every repaint of
the Mainform.
This is happening, everytime when I'm using the device in any form.
I'd tried to place the methods InitializeDevice and RenderScenegraph in the
Mainform but without any effects.
So my question is, can anyone help me, to solve the problem of increasing
memory-use?
cu Thomas
I'm new to managed DirectX and have a great problem with memory leaks.
I think, its the best when I tell you something about the project and the
structure of the project.
The goal of the project is to render a scenegraph in a control ( I use a
panel as control, because I mentioned, that the picture box is buggy for
this).
Becuase there can be a lot of different objects I have written an own class
for rendering. The class is named RenderMain and is established in an own
assembly with other classes. This class has a property for the device and a
property for the control. The Mainform is established in an other assembly.
I'd overriden the OnPaint-Method of the Mainform like this:
Code:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Application.DoEvents();
if (m_RenderMain!=null)
m_RenderMain.PaintDevice();
this.Invalidate();
}
Code:
public void PaintDevice()
{
m_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
System.Drawing.Color.Black,1f,0);
m_device.BeginScene();
m_device.RenderState.Lighting=true;
m_device.RenderState.CullMode=Cull.None;
if (m_IsViewpointDefined==false)
SetupStandardCamera();
if (m_IsLightDefined==false)
m_device.RenderState.Ambient=System.Drawing.Color.White;
ReadScenegraph();
m_device.EndScene();
m_device.Present();
}
purpose, every item of the scenegraph have a method which looks like thius:
Code:
public Device Action(Device directXDevice)
{
//render item
return directXdevice;
}
Code:
public void InitializeDevice()
{
PresentParameters myPresentParameters= new PresentParameters();
myPresentParameters.Windowed=true;
myPresentParameters.SwapEffect=SwapEffect.Discard;
myPresentParameters.AutoDepthStencilFormat=DepthFormat.D16;
myPresentParameters.EnableAutoDepthStencil=true;
int adapterOrdinal=Manager.Adapters.Default.Adapter;
CreateFlags flags= CreateFlags.SoftwareVertexProcessing;
//Check to see, if we can use a pure hardw<redevice
Caps caps=Manager.GetDeviceCaps(adapterOrdinal,DeviceType.Hardware);
if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
{
//Replace softwarevertex with hardwarevertex
flags=CreateFlags.HardwareVertexProcessing;
}
//Do we support pure device?
if (caps.DeviceCaps.SupportsPureDevice)
flags |=CreateFlags.PureDevice;
m_device=new
Device(adapterOrdinal,DeviceType.Hardware,m_control,flags,myPresentParameter
s);
}
taskmanager, I see, that the memory-use is increasing by every repaint of
the Mainform.
This is happening, everytime when I'm using the device in any form.
I'd tried to place the methods InitializeDevice and RenderScenegraph in the
Mainform but without any effects.
So my question is, can anyone help me, to solve the problem of increasing
memory-use?
cu Thomas