0

Cannot access a disposed object. Object name: 'BasicEffect'.

This exeption is thrown whenever I try to load a model from a list. The method used to work but has recently failed and I do not know why.

Below is my render code:

public void RenderModel(Model m, Vector3 ModelPosition,  float rotY = 0, float rotX = 0, float rotZ = 0, bool lit = true, bool collision = false)  
{  
    if (m != null)  
    {  
        Matrix[] transforms = new Matrix[m.Bones.Count];    
        m.CopyAbsoluteBoneTransformsTo(transforms);  

        float rotationZ = rotZ * (float)(Math.PI / 180);
        float rotationY = rotY * (float)(Math.PI / 180);
        float rotationX = rotX * (float)(Math.PI / 180);

        foreach (ModelMesh mesh in m.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                if (lit == true)
                {
                    //effect.EnableDefaultLighting();
                }
                effect.World = transforms[mesh.ParentBone.Index] *
                    Matrix.CreateRotationY(rotationY) *
                    Matrix.CreateRotationX(rotationX) *
                    Matrix.CreateRotationZ(rotationZ) *
                 Matrix.CreateTranslation(ModelPosition);
                effect.View = view;
                effect.Projection = proj;
            }
            mesh.Draw();
        }
    }
}

And then my list code (Path being the path of the model)

public void AddModel(string Path)  
{  
    Model newModel;  
    newModel = Content.Load<Model>(Path);  
    renderModels.Add(newModel);  
}

And finally the Draw code, Put in the draw method.

foreach (Model m in renderModels)  
{  
    camera.RenderModel(m, new Vector3(0,0,0));  
}  

Just to clarify, I need this for a level editor for a game my small team have been working on. Any help is much appreciated.

user1306322
  • 8,561
  • 18
  • 61
  • 122
Jed
  • 1
  • 1
  • Consider http://xboxforums.create.msdn.com/forums/t/51107.aspx .It may help you – Dmitrii Dovgopolyi Oct 13 '13 at 21:44
  • "The method used to work but has recently failed", what have you changed? – pinckerman Oct 13 '13 at 23:50
  • @DmitryDovgopoly Thanks for the link, but there are no calls in the Game method, and the graphics.IsDisposed is false when the content is loaded so unfortunately this does not resolve the problem. – Jed Oct 14 '13 at 17:39
  • @pincknerman I have added a content.Unload call when the method is called, which allows me to change the content rootdirectory, Before reloading the content from the list. I hope this helps. – Jed Oct 14 '13 at 17:41

0 Answers0