AccessViolationException when trying to render a sphere

Apr 6, 2013 at 5:31 PM
I'm liking the library so far, but I've run into a problem.

I'm trying to draw a series of spheres on the screen and when I do I get an AccessViolationException.
  public void draw_sphere(OpenGL gl, Color color, IAgent agent)
        {
            Sphere sphere = new SharpGL.SceneGraph.Quadrics.Sphere();
            sphere.Radius = agent.Radius;
            GLColor glClr = new GLColor(color.R, color.G, color.B, color.A);
            OpenGLAttributesEffect glEffect = new OpenGLAttributesEffect();
            glEffect.ColorBufferAttributes.ColorModeClearColor = glClr;
            glEffect.ColorBufferAttributes.ColorModeWriteMask = glClr;

            sphere.NormalGeneration = SharpGL.SceneGraph.Quadrics.Normals.Smooth;
            sphere.NormalOrientation = SharpGL.SceneGraph.Quadrics.Orientation.Outside;
            sphere.QuadricDrawStyle = SharpGL.SceneGraph.Quadrics.DrawStyle.Fill;
            sphere.AddEffect(glEffect);

            sphere.Slices = 100;
            sphere.Stacks = 100;
            sphere.TextureCoords = false;

            sphere.PushObjectSpace(gl);
            sphere.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            sphere.PopObjectSpace(gl);
        }

        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            gl.LoadIdentity();

            gl.Begin(OpenGL.GL_QUADS);
            for (int i = 0; i < this._viewModel.Agents.Count; i++)
            {
                this.draw_sphere(gl, this._viewModel.Agents[i].DetermineColor(), this._viewModel.Agents[i]);
            }
            gl.End();
            
        }
I'm not sure why this is occurring. Anyone have any ideas?
Coordinator
Apr 6, 2013 at 5:57 PM
I'll raise a task to investigate the exception - access violation exceptions are pretty bad, it may be a bug in SGL
Coordinator
Apr 6, 2013 at 5:58 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 6, 2013 at 6:59 PM
So I think I figured out why this is occurring and this is partially my fault. I didn't call the CreateInContext method. This initializes the glQuadric variable within the base Quadric class. I am no longer getting the error message, but the application locks up for some reason. I'm trying to track this down now.
Apr 10, 2013 at 3:47 PM
I have the same problem but it occurs on this function DoHitTest(), and after, this one RenderElementForHitTest(). I don't know what i can do to fix it :(