This project is read-only.

AcessViolation Exception Unhandled in XNA Animation Lib

May 11, 2009 at 8:05 PM

I have successfully used the animation library, although my animations still need work. However am noticing that

whenever I exit my game, I get an exception in this piece of code in ModelAnimator.cs. I am thinking this may be

happening as the content is being unloaded due to the exit operation. Does anyone have suggestions on what

the problem may be, any experience with debugging the animation library dll, a procedure will be helpful. 

thanks to open source, all problems can be solved.

 

        public override void Draw(GameTime gameTime)
        {
            try
            {
                int index = 0;
                // Update all the effects with the palette and world and draw the meshes
                for (int i = 0; i < numMeshes; i++)
                {
                    ModelMesh mesh = model.Meshes[i];
                    // The starting index for the modelEffects array
                    int effectStartIndex = index;
                    if (matrixPaletteParams[index] != null)
                    {
                        foreach (Effect effect in mesh.Effects)
                        {
                  
                                worldParams[index].SetValue(
              
                                    world);
                           

                            matrixPaletteParams[index].SetValue(palette[i]);
                            index++;
                        }
                    }
                    else
                    {
                        foreach (Effect effect in mesh.Effects)
                        {

                            worldParams[index].SetValue(pose[mesh.ParentBone.Index] * world);
                            index++;
                        }
                    }
                    int numParts = mesh.MeshParts.Count;
                    GraphicsDevice device = mesh.VertexBuffer.GraphicsDevice;
                    device.Indices = mesh.IndexBuffer;
                    for (int j = 0; j < numParts; j++ )
                    {
                        ModelMeshPart currentPart = mesh.MeshParts[j];
                        if (currentPart.NumVertices == 0 || currentPart.PrimitiveCount == 0)
                            continue;
                        Effect currentEffect = modelEffects[effectStartIndex+j];
     

                        device.VertexDeclaration = currentPart.VertexDeclaration;
                        device.Vertices[0].SetSource(mesh.VertexBuffer, currentPart.StreamOffset,
                            currentPart.VertexStride);

                        currentEffect.Begin();
                        EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;
                        int numPasses = passes.Count;
                        for (int k = 0; k < numPasses; k++)
                        {
                            EffectPass pass = passes[k];
                            pass.Begin();
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, currentPart.BaseVertex,
                                0, currentPart.NumVertices, currentPart.StartIndex, currentPart.PrimitiveCount);
                            pass.End();
                        }

                        currentEffect.End();
                    }
                }
            }
            catch (NullReferenceException)
            {
                throw new InvalidOperationException("The effects on the model for a " +
                    "ModelAnimator were changed without calling ModelAnimator.InitializeEffectParams().");
            }
            catch (InvalidCastException)
            {
                throw new InvalidCastException("ModelAnimator has thrown an InvalidCastException.  This is " +
                    "likely because the model uses too many bones for the matrix palette.  The default palette size "
                    + "is 56 for windows and 40 for Xbox.");
            }
           
        }