This project is read-only.

AccessViolationException when trying to render a sphere

Apr 6, 2013 at 6: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.Slices = 100;
            sphere.Stacks = 100;
            sphere.TextureCoords = false;

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

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

            for (int i = 0; i < this._viewModel.Agents.Count; i++)
                this.draw_sphere(gl, this._viewModel.Agents[i].DetermineColor(), this._viewModel.Agents[i]);
I'm not sure why this is occurring. Anyone have any ideas?
Apr 6, 2013 at 6:57 PM
I'll raise a task to investigate the exception - access violation exceptions are pretty bad, it may be a bug in SGL
Apr 6, 2013 at 6: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 7: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 4: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 :(