我的C#应用程序存在问题。它应该是一个DirectX / D3D游戏覆盖图,向我展示我在Spotify上听到的当前歌曲。这是绘图代码:
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;
}
所以它访问了我在这里制作的DrawPicture函数:
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();
}
但是30秒后,应用程序崩溃并出现以下异常:
Microsoft.DirectX.Direct3DX.dll中的“Microsoft.DirectX.Direct3D.Direct3DXException”类型的异常(第一次机会)已被播出。
对不起我的英文,但错误信息是像我这样的德语:) 当我查看任务管理器时,它说我的应用程序获得内存,直到达到1GB的RAM然后崩溃。有什么能更好地画出那个精灵吗? 谢谢!