RE: Exception raised when drawing many circles



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.
>
>
.



Relevant Pages

  • Re: Delegation and Taskpads
    ... Best regards ... This posting is provided "AS IS" with no warranties, and confers no rights. ... But I'm still looking for how to put the unlock feature in a taskpad. ... "Meinolf Weber" wrote: ...
    (microsoft.public.windows.server.active_directory)
  • Re: Unlock Workstation Programmatically,...
    ... develop applications that can unlock the WS,.. ... Beste Grüsse / Best regards / Votre bien devoue ...
    (microsoft.public.win32.programmer.kernel)
  • Re: HOW TO UNLOCK ENCRIPTED FILES
    ... You have to choose the recovery agent in the domain for decrypting. ... Best regards ... This posting is provided "AS IS" with no warranties, ... to unlock these files or we can´t. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Unlock sharp GX30i on Vodafone
    ... Laurie wrote: ... Anyone know how to unlock this phone, or where is the cheapest place to get it done? ... Regards, ...
    (uk.telecom.mobile)
  • RE: smooth progress bar flickering
    ... Also you may try to use LockWindowUpdate API to lock the window before ... update and then unlock after update to see if this helps you. ... Best regards, ...
    (microsoft.public.dotnet.languages.vb)

Loading