MAS's picture

newbie wows

hi,

I have been trying to get going using openTK and am creating primitives ok. I am using v 1.1.1475.5656 glcontrol in a winform. so for example a simple cylinder with 10 control points work absolutely fine (so I don't believe theres a problem with the mesh generation). But as soon as the cylinder control points gets to a certain size eg: 60 points on the circle edge the app crashes with a first chance exception of type 'System.AccessViolationException' occurred in OpenTK.dll when I call GL.CallList(DisplayListHandle) in the Draw method, on a valid display list handle (yes I know I should start using VBO / IBO's), Ive tried GL.Error and its returning NoError and I've tried putting GLFinish() before the call to CallList() (believing the this makes sure that the GPU has finished everything it was doing.

no doubt this is something I am doing wrong but I just cannot figure out what? I would be very grateful for any pointers. Many thanks.

        public void Draw()
        {
            try
            {
                if (!UseDisplayList)
                    DrawImmediateMode();
                else
                    if (DisplayListHandle == 0)
                    {
                        this.Regenerate(_renderingOptions);
                    }
                    else
                    {
                        ErrorCode v = GL.GetError();
                        if (v.ToString() != "NoError")
                        {
                            Console.WriteLine(v.ToString());
                        }
                        GL.CallList(DisplayListHandle);
 
                    }
            }
            catch(Exception ex)
            {
 
            }
 
        }

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MAS's picture

Hi,

It appears that I can answer my own question I appear to have resolved the problem by putting a GL.Finish() and then GL.Flush() at the end of my render loop but is this the correct thing to do or does it hint the there are fundamental problems with my code?

Many thanks

the Fiddler's picture

GL.Finish() and GL.Flush() should not affect anything, it's very likely there is a bug hiding elsewhere in the code.

Can you also post the code for DrawImmediateMode and Regenerate?

MAS's picture
        public virtual void DrawImmediateMode()
        {
            if (IndexArray != null && VertexArray != null)
            {
                GL.Begin(PrimitiveMode);
                {
                    if (IndexArray == null)
                        foreach (VertexT2dN3dV3d v in VertexArray)
                        {
                            GL.TexCoord2(v.TexCoord.X, v.TexCoord.Y);
                            GL.Normal3(v.Normal.X, v.Normal.Y, v.Normal.Z);
                            GL.Vertex3(v.Position.X + Transform.Translate.x, v.Position.Y + Transform.Translate.y, v.Position.Z + this.Transform.Translate.z);
 
                        }
                    else
                    {
                        for (uint i = 0; i < IndexArray.Length; i++)
                        {
                            uint index = IndexArray[i];
                            GL.TexCoord2(VertexArray[index].TexCoord.X, VertexArray[index].TexCoord.Y);
                            GL.Normal3(VertexArray[index].Normal.X, VertexArray[index].Normal.Y, VertexArray[index].Normal.Z);
                            GL.Vertex3(VertexArray[index].Position.X, VertexArray[index].Position.Y, VertexArray[index].Position.Z);
                        }
                    }
                }
                GL.End();
            }
        }
MAS's picture

If I try and post regenerate and preview it says that I am triggering a spam filter???? (not sure what that says about the quality of my code ;o)

MAS's picture

a short version of regen!

        public void Regenerate(RenderingType renderingOptions)
        {
            _renderingOptions = renderingOptions;
            if (DisplayListHandle != 0)
            {
                GL.Finish();
                GL.DeleteLists(DisplayListHandle, 1);
                DisplayListHandle = 0;
            }
            if (DisplayListHandle == 0)
            {
                GL.Finish();
                DisplayListHandle = GL.GenLists(1);
                GL.NewList(DisplayListHandle, ListMode.Compile);
            }
                if ((renderingOptions & RenderingType.Solid) == RenderingType.Solid)
                {
                    this.PrimitiveMode = PrimitiveType.Triangles;
                    GL.Enable(EnableCap.PolygonOffsetFill);
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    GL.PolygonOffset(1, 1);
                    GL.Color4(1.0f, 1.0f, 1.0f, 0.5f);
                    //GL.Color3(_SolidColor);
 
                    DrawImmediateMode();
                    if (this.GetType() == typeof(Polyline))
                    {
                        this.PrimitiveMode = PrimitiveType.Lines;
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        GL.LineWidth(1);
                        GL.Color3(Color.Black);
 
                        DrawImmediateMode();
                        this.PrimitiveMode = PrimitiveType.Points;
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
                        GL.PointSize(3);
 
                        GL.Color3(Color.Red);
                        DrawImmediateMode();
 
                    }
                }
 
                if ((renderingOptions & RenderingType.None) == RenderingType.None)
                {
                    DrawImmediateMode();
                }
            }
            GL.EndList();
            GL.CallList(DisplayListHandle);
            //Console.WriteLine("regen called");
        }
the Fiddler's picture

Nothing really jumps as out of place. Does it also crash if you set UseDisplayList to false?

MAS's picture

Yup,

Well thanks for taking a look at the code for me fiddler, I'm sure I will get to the bottom of it eventually..and if I figure it out will let you know

GL.Finish() and GL.Flush() after rendering does seem to make the problem go away though!

the Fiddler's picture

In that case where does it crash when you UseDisplayLists is false? This might give a hint about what is going wrong.

The other (and probably best) alternative would be to use apitrace to record what exactly is happening. This will give you a trace of all OpenGL calls that you can inspect for errors (and even modify and replay.)

MAS's picture

well,

I got there it was a GL newbie mistake trying to render line primitives and triangle primitives with the same render code.....

thanks for your help