Re-Using Model instances pointing to Models in List in turn causes error after 3 re-use

Hi all,

I hope to be clear :slight_smile:

I load 10 Models in 10 different Model objects say:

Model a;
Model b;

a = Content.Load(“a”);
b = Content.Load(“b”);

Then I store these models into a List
models = new List();


then I have a Model p that points to the first object in the List

p = models[0];

after pressing a key, p is assigned to the next list element

p = models[1]

Obviously, the model is drawed in the Draw() function.

All works correctly except that after the third model I’ve the error below.

I’ve tried to load and draw all models one by one and I’ve no error.

Exception thrown: ‘SharpDX.SharpDXException’ in SharpDX.dll
Exception thrown: ‘SharpDX.SharpDXException’ in SharpDX.dll
Exception thrown: ‘System.InvalidOperationException’ in MonoGame.Framework.dll
An unhandled exception of type ‘System.InvalidOperationException’ occurred in MonoGame.Framework.dll
An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, TEXCOORD0.

**‘MG - SauroTest.exe’ (CLR v4.0.30319: MG - SauroTest.exe): Loaded ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll’. **
The program ‘[8752] MG - SauroTest.exe’ has exited with code -1 (0xffffffff).

Are all your models exported the same way? Are you using the same shader for each? It says your model has position and texture coordinate values for each vertex, but the vertex declaration is missing something else that’s expected by the shader.

I’ve tested again loading one by one and found that one model has something wrong. Thank you.

yesterday I did the same test but maybe that being tired I made something wrong :slight_smile:

thank you