XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Problem loading content via a thread

Last post 03/06/2009 14:16 by dadoo Games. 2 replies.
  • 03/06/2009 10:49

    Problem loading content via a thread

    Hi

    I have split my loading up into a couple of threads because there is a big load for the game.

    The problem that I get is when i try to load in a model and the error message that I get is:

    Error:
    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
    Additional information: Value does not fall within the expected range.


    The error occurs within this code:

    public void LoadModel(string fileName, Effect Effect, ContentManager content) 
         //effect = Effect; 
         Model = content.Load<Model>(fileName); 
         absoluteTransforms = new Matrix[Model.Bones.Count]; 
     
         for (int i = 0; i < Model.Meshes.Count; i++) 
         { 
             modelParts.Add(new ModelPart(Model.Meshes[i])); 
             modelParts[modelParts.Count - 1].Effect = effect; 
         } 

    Each thread has it's own ContentManager instance so that they don't conflict when loading.

    Any ideas as to what the problem is and how it could be resolved

    Thanks
    Andy
  • 03/06/2009 11:35 In reply to

    Re: Problem loading content via a thread

    I believe I have found the problem.

    The error only happens when loading Models and not textures.
    I think this is because the Models needs to use the GraphicsDevice when loading in the background and that it conflicts when loading models in different threads.

    e.g.

    Thread 1
    Load Model 1
    Load Model 2

    Thread 2
    Load Model 3
    Load Model 4

    I believe that when loading a Model on one thread it locks out or restricts the other thread from allowing use to the GraphicsDeivce.

    e.g.
    Model 1 is being loaded
    Model 3 tries to load but throws an error because Model1 has taken control of the GraphicsDevice

    This maybe incorrect but it is just my theory on the issue

  • 03/06/2009 14:16 In reply to

    Re: Problem loading content via a thread

    Any thread that accesses the GraphicsDevice locks it across all threads, so it's not unexpected. See here for a good explanation.
    www.dadoogames.com
    Curling 2010 - in playtest soon, this month or next, this year for sure (maybe)
Page 1 of 1 (3 items) Previous Next