Sign in to follow this  
f8k8

XNA: InvalidOperationException when loading models on 360

Recommended Posts

f8k8    171
I posted this on the creators club forums, but didn't get any responses. Hoping someone here might know, so I'm reposting here. The original thread is here: We've got a loading thread to load in assets behind the loading screen. All it does at the moment load all the textures/models etc and then signal that it's done. The main thread just prints the text "Loading..." on screen, nothing more. Sometimes though (maybe about 30 - 40% of the time), we're getting an InvalidOperationException : This resource could not be created thrown. It's always on the same model, which is about a third of the way into our list of models. Before loading the models, it loads in some sprite textures too. Is there anything you have to take into consideration when loading in a separate thread to the main thread? Nothing is being created by the main thread during the load. Like I said, all it does is render some text that says "Loading..." with a sprite font that gets created in the LoadContent function. The loading thread gets kicked off in the Initialize function of the main Game class, after the call to base.Initialize(). Any ideas? It only seems to do it on 360, not Windows. I've posted the callstack if it'll be any help:
Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Graphics.VertexDeclaration.VertexDeclaration(Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice = {Microsoft.Xna.Framework.Graphics.GraphicsDevice}, Microsoft.Xna.Framework.Graphics.VertexElement[ elements = {Dimensions:[4]}) + 0x6b bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.VertexDeclarationReader.Read(Microsoft.Xna.Framework.Content.ContentReader input = {Microsoft.Xna.Framework.Content.ContentReader}, Microsoft.Xna.Framework.Graphics.VertexDeclaration existingInstance = null) + 0x71 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.InvokeReader<Microsoft.Xna.Framework.Graphics.VertexDeclaration>(Microsoft.Xna.Framework.Content.ContentTypeReader reader = {Microsoft.Xna.Framework.Content.VertexDeclarationReader}, object existingInstance = null) + 0x23 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.ReadObjectInternal<Microsoft.Xna.Framework.Graphics.VertexDeclaration>(object existingInstance = null) + 0x40 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.ReadObject<Microsoft.Xna.Framework.Graphics.VertexDeclaration>()   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Graphics.Model.ReadVertexDeclarations(Microsoft.Xna.Framework.Content.ContentReader input = {Microsoft.Xna.Framework.Content.ContentReader}) + 0x15 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Graphics.Model.Read(Microsoft.Xna.Framework.Content.ContentReader input = {Microsoft.Xna.Framework.Content.ContentReader}) + 0xd bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ModelReader.Read(Microsoft.Xna.Framework.Content.ContentReader input = {Microsoft.Xna.Framework.Content.ContentReader}, Microsoft.Xna.Framework.Graphics.Model existingInstance = null)   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.InvokeReader<Microsoft.Xna.Framework.Graphics.Model>(Microsoft.Xna.Framework.Content.ContentTypeReader reader = {Microsoft.Xna.Framework.Content.ModelReader}, object existingInstance = null) + 0x23 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.ReadObjectInternal<Microsoft.Xna.Framework.Graphics.Model>(object existingInstance = null) + 0x40 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.ReadObject<Microsoft.Xna.Framework.Graphics.Model>()   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentReader.ReadAsset<Microsoft.Xna.Framework.Graphics.Model>() + 0x7 bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentManager.ReadAsset<Microsoft.Xna.Framework.Graphics.Model>(string assetName = "Content\\Models\\Block_PS135_Y", System.Action<System.IDisposable> recordDisposableObject = null) + 0x3a bytes   
  Microsoft.Xna.Framework.dll!Microsoft.Xna.Framework.Content.ContentManager.Load<Microsoft.Xna.Framework.Graphics.Model>(string assetName = "Content\\Models\\Block_PS135_Y") + 0x85 bytes   
> Game360.exe!GameBB.CXnaApplication.LoadModels(string Filename = "Content\\Config\\Models.xml") Line 470 + 0x15 bytes C#  
  Game360.exe!GameBB.CXnaApplication.LoadGameContent() Line 524 + 0xb bytes C#  

Share this post


Link to post
Share on other sites
MJP    19788
To my best knowledge it's only safe to use a ContentManager with the thread that was used to create it. If you want to make a loading thread, you need to make a new ContentManager with that thread and only use that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this