Game Development for Xbox 360, PC + Windows Phone 7

Missing Code - Page 77 - Errata Needed

rated by 0 users
This post has 1 Reply | 2 Followers

Top 10 Contributor
Male
Posts 21
garfbradaz Posted: 19 Aug 2010 3:55 PM

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"
 

Top 10 Contributor
Male
Posts 136

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

Page 1 of 1 (2 items) | RSS
© 2011 Chad Carter. All rights reserved.