I have a problem here with my C# application. It should be a DirectX / D3D Game overlay to show me current song I hear on Spotify. This is the drawing code:
private void dxThread()
{
while (!_StopThread)
{
#region DeviceWork
device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
device.RenderState.ZBufferEnable = false;
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
device.Transform.Projection = Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1);
device.BeginScene();
#endregion
#region Drawing
IntPtr handle = FindWindow(null, WindowName);
if (handle != IntPtr.Zero)
{
RECT wrect = GetWindowRect(handle);
switch (OverlayCustomizer.bg_source)
{
case 0: //Default
DrawPicture(wrect.Left, wrect.Top, SpotifyOverlay.Properties.Resources.Default_Background, OverlayCustomizer.bg_tint);
break;
case 1: //Simple color
FillRect(wrect.Left, wrect.Top, OverlayCustomizer.size_x, OverlayCustomizer.size_y, OverlayCustomizer.bg_simple_color);
break;
case 2: //Custom
break;
default:
break;
}
}
#endregion
device.EndScene();
device.Present();
}
this.device.Dispose();
ThreadOver = true;
}
So it accesses there a DrawPicture function which I made here:
public void DrawPicture(float x, float y, Bitmap bitmap, Color tint)
{
Texture texture;
Rectangle textureSize;
texture = new Texture(device, bitmap, Usage.None, Pool.Managed);
using (Surface surface = texture.GetSurfaceLevel(0))
{
SurfaceDescription sd = surface.Description;
textureSize = new Rectangle(0, 0, sd.Width, sd.Height);
}
Sprite sprite = new Sprite(device);
sprite.Begin(SpriteFlags.None);
sprite.Draw(texture, textureSize, new Vector3(0, 0, 0), new Vector3(x, y, 0), tint);
sprite.End();
}
But after 30 seconds the application crashes with following exception:
An exception (first Chance) of type "Microsoft.DirectX.Direct3D.Direct3DXException" in Microsoft.DirectX.Direct3DX.dll was trown.
Sorry for my english but the error message is german like me :) When I look in the Task Manager it says my Application gains memory till it reaches 1GB of RAM and then it crashes. Anything to draw that sprite better? Thanks!