XNA Essentials

Game Programming for Xbox 360, PC + Windows Phone

NAVIGATION - SEARCH

Missing Code - Page 77 - Errata Needed

Hi Chad,

On page 77 you are missing the following line of code from the new Draw method:


 



graphics.GraphicsDevice.VertexDeclaration = _vertexDeclaration;


Otherwise you get an exception


System.InvalidOperationException was unhandled
  Message="A valid vertex declaration must be set on the device before any draw operations can be performed."
  Source="Microsoft.Xna.Framework"
 


garfbradaz - Thursday, August 19, 2010 @ 3:55 PM

Re: Missing Code - Page 77 - Errata Needed

The code is in place at the top of page 74. 


----------------------------------------------------------


Finally, we can change the original statement inside of Draw to set graphics device vertex
declaration to the variable we just initialized:


graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration;


Now we are only creating the vertex declaration once and setting it once instead of every
frame. This is encouraging because we are now at about 3,230 fps on the Xbox 360 and
the performance is still the same on Machine A at about 207 fps. So just with a little bit of
effort we optimized our code from running at a mere 114 fps on the Xbox 360 to a more
reasonable 3,230 fps.


--------------------------------------------


Hope this helps,


Chad

Chad Carter - Monday, August 23, 2010 @ 7:25 AM