RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger <utanapishtim@xxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Sep 2005 01:06:02 -0700
Hello Rhett,
I have finally been able to reproduce the crash on a simple application.
Here is the code for an application based on a Windows Form (the code
generated by the designer is unchanged).
You will notice that an exception is raised during the call to
Line.DrawTransform(). The debug message of Direct3D is "Direct3D9: (ERROR)
:Index stream does not have required number of indices. DrawIndexedPrimitive
failed."
------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace TestD3D
{
partial class Form8 : Form
{
private DeviceType deviceType = DeviceType.Hardware;
private Device d3device;
private Line liner;
private Vector3[] polyline;
private Vector3[] polylineTra;
public Form8()
{
InitializeComponent();
}
private Format GetBackBufferFormat()
{
if (Manager.CheckDeviceType(0, deviceType,
Manager.Adapters[0].CurrentDisplayMode.Format, Format.X8R8G8B8, true))
return Format.X8R8G8B8;
if (Manager.CheckDeviceType(0, deviceType,
Manager.Adapters[0].CurrentDisplayMode.Format, Format.R5G6B5, true))
return Format.R5G6B5;
return Format.Unknown;
}
private DepthFormat GetDepthFormat(Format backFormat)
{
if (Manager.CheckDepthStencilMatch(0, deviceType,
Manager.Adapters[0].CurrentDisplayMode.Format, backFormat, DepthFormat.D24X8))
return DepthFormat.D24X8;
if (Manager.CheckDepthStencilMatch(0, deviceType,
Manager.Adapters[0].CurrentDisplayMode.Format, backFormat, DepthFormat.D16))
return DepthFormat.D16;
return DepthFormat.Unknown;
}
private void InitializeDirect3D()
{
PresentParameters parameters = new PresentParameters();
CreateFlags createFlags = CreateFlags.FpuPreserve;
Format format;
DepthFormat depthFormat;
format = GetBackBufferFormat();
depthFormat = GetDepthFormat(format);
parameters.Windowed = true;
parameters.BackBufferFormat = format;
parameters.AutoDepthStencilFormat = depthFormat;
parameters.EnableAutoDepthStencil = true;
parameters.SwapEffect = SwapEffect.Discard;
parameters.PresentationInterval = PresentInterval.One;
parameters.BackBufferCount = 1;
parameters.PresentFlag = PresentFlag.DeviceClip |
PresentFlag.DiscardDepthStencil;
Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);
parameters.BackBufferWidth = rect.Width;
parameters.BackBufferHeight = rect.Height;
parameters.DeviceWindow = this;
if (Manager.GetDeviceCaps(0,
this.deviceType).DeviceCaps.SupportsHardwareTransformAndLight)
createFlags |= CreateFlags.HardwareVertexProcessing;
else
createFlags |= CreateFlags.SoftwareVertexProcessing;
this.d3device = new Device(0, this.deviceType, this, createFlags,
parameters);
this.d3device.RenderState.ColorVertex = false;
this.d3device.RenderState.ZBufferEnable = false;
this.d3device.RenderState.AlphaBlendEnable = false;
this.d3device.RenderState.AlphaTestEnable = false;
this.d3device.RenderState.CullMode = Cull.None;
this.liner = new Line(d3device);
SetupBuffersRH();
}
private void SetupBuffersRH()
{
int count = 144;
double radius = 1.0;
double angle;
this.polyline = new Vector3[count + 1];
this.polylineTra = new Vector3[count + 1];
for (int i = 0; i <= count; i++)
{
angle = i * 2.0 * Math.PI / count;
this.polyline[i] = new Vector3(
(float)(radius * Math.Cos(angle)),
(float)(radius * Math.Sin(angle)),
0.0f);
}
}
public void PaintRender()
{
int circleCount = 10;
Rectangle[] rects = new Rectangle[1];
rects[0] = this.ClientRectangle;
d3device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
Color.FromArgb(0, 0, 160), 1.0f, 0, rects);
float aspect = (float)this.ClientRectangle.Width /
(float)this.ClientRectangle.Height;
float height = 10.0f;
float width = height * aspect;
Viewport viewport = new Viewport();
viewport.X = 0;
viewport.Y = 0;
viewport.Width = this.ClientRectangle.Width;
viewport.Height = this.ClientRectangle.Height;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
d3device.Viewport = viewport;
d3device.Transform.Projection = Matrix.OrthoRH(width, height, 1.0f, 10.0f);
d3device.Transform.View = Matrix.LookAtRH(
new Vector3(0.0f, 0.0f, 5.0f),
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f));
Matrix pv = d3device.Transform.View * d3device.Transform.Projection;
Random rnd = new Random(0);
this.liner.Width = 3;
this.liner.PatternScale = 1.0f;
this.liner.Pattern = -1;
this.liner.Begin();
for (int i = 0; i < circleCount; i++)
{
float trax = (float)(10.0 * rnd.NextDouble() - 5.0);
float tray = (float)(10.0 * rnd.NextDouble() - 5.0);
for (int j = 0; j < this.polyline.Length; j++)
{
this.polylineTra[j] = this.polyline[j];
this.polylineTra[j].X += trax;
this.polylineTra[j].Y += tray;
}
this.liner.DrawTransform(this.polylineTra, pv, Color.White);
}
this.liner.End();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
InitializeDirect3D();
}
protected override void OnPaint(PaintEventArgs e)
{
d3device.BeginScene();
PaintRender();
d3device.EndScene();
d3device.Present(this.ClientRectangle, this, true);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}
}
}
------------------------------------------------
I hope this will help you.
Best regards.
--
Olivier Lauffenburger
Missler Software
"Rhett Gong [MSFT]" wrote:
> Hello Olivier,
> Yes, if UnLock is not called, Draw* call will not succeed. I understand your scenario, but I have no more details to tell why
> the vertex buffer is not unlocked.
> So that I could better assist you digging into this problem, could you try make a simple repro sample or isolate your project
> into a small pieces of code?
>
> Thank you for your patience.
>
> Best regards,
> Rhett Gong [MSFT]
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp&SD=msdn
>
> This posting is provided "AS IS" with no warranties and confers no rights.
>
>
.
- Follow-Ups:
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- References:
- Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- Exception raised when drawing many circles
- Prev by Date: Wordwrapping with 3D text
- Next by Date: Texas Quest: 2D Game in Managed DirectX and C#
- Previous by thread: RE: Exception raised when drawing many circles
- Next by thread: RE: Exception raised when drawing many circles
- Index(es):
Relevant Pages
|
Loading