problem with run samples

Jul 1, 2008 at 7:23 AM
I downloaded XNAnimation 0.7.0 and I have problem with run samples. when I debuging code I receive "{"Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed."}". what should I do?
Jul 1, 2008 at 8:21 AM

Are you trying the sample that comes with the source code, or one of the samples that come with the release?
Which sample are you trying?  AnimationControllerSample1, AnimationControllerSample2 or the BlendAnimationSample?

This error is because something is being rendered before an valid effect be set.
Jul 1, 2008 at 8:52 AM
unfortunately all samples, with source and release
Jul 1, 2008 at 3:34 PM
I've downloaded the 0.7 release with samples again and it worked fine here. Can you try to run the AnimationControllerSample1 and past the complete exception here, so I can see with lines are throwing this exceptions?

As I said it should only happens if you try to draw something before setting a valid shader.
Jul 2, 2008 at 7:06 AM
i think problem is in the version pixel or vertex shader. i run all samples on another computer (with geforce 6800gs) and everything is ok, but on ati x300/550 (support ps2.0) crushed on "modelMesh.Draw();"

System.InvalidOperationException was unhandled
  Message="Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed."
       at Microsoft.Xna.Framework.Graphics.GraphicsDevice.VerifyCanDraw(Boolean bUserPrimitives, Boolean bIndexedPrimitives)
       at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 minVertexIndex, Int32 numVertices, Int32 startIndex, Int32 primitiveCount)
       at Microsoft.Xna.Framework.Graphics.ModelMeshPart.Draw()
       at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw(SaveStateMode saveStateMode)
       at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
       at AnimationControllerSample1.XNAnimationSample.Draw(GameTime gameTime) in D:\xn\XNAnimation Samples\AnimationControllerSample1\XNAnimationSample.cs:line 134
       at Microsoft.Xna.Framework.Game.DrawFrame()
       at Microsoft.Xna.Framework.Game.Paint(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameWindow.OnPaint()
       at Microsoft.Xna.Framework.WindowsGameWindow.mainForm_Paint(Object sender, PaintEventArgs e)
       at System.Windows.Forms.Control.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Form.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
       at System.Windows.Forms.Control.WmPaint(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at Microsoft.Xna.Framework.WindowsGameForm.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at Microsoft.Xna.Framework.Input.UnsafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
       at Microsoft.Xna.Framework.Input.WindowMessageHooker.Hook.WndProc(IntPtr msgWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.Run()
       at AnimationControllerSample1.XNAnimationSample.Main(String[] args) in D:\xn\XNAnimation Samples\AnimationControllerSample1\XNAnimationSample.cs:line 159


Jul 2, 2008 at 6:54 PM
Sorry for the late reply.

The samples on the XNAnimation are using Vertex Shader 2_0 and Pixel Shader 2_A. I googled and found that the ATI x300 does support Shader Model 2.0 but I'm not sure if it supports PS 2_A, apparently not since you are having problems with it.

Can you run GPU-Z (just google for gpu-z) and look if you video card supports SM 2_A? You can find this information on the DirectX field on gpu-z. I will try to optimize this shader and make the two_light technique uses Shader Model 2.0.
Jul 2, 2008 at 7:12 PM
It is really strange because on ATI website it says that x300 Pixel Shader supports up to 160 instructions, and the animated model shader has only 90 instructions. So, it should work.
Maybe the problem is with PS 2_A, maybe using PS 3_0 should work...

You can also try this on the samples:

// After the OPTIONAL shader configuration add this
effect.EnabledLights = EnabledLights.Four;

This will make the effect chage its profile to shader model 3.0 and maybe it works.
Jul 3, 2008 at 8:13 AM
As far as I know those ATI CG supports only up to PS 2_0.
I've got an x600 here and have been having the same issues on other samples. The only way to make things work was to set PS to 2_0...
Jul 3, 2008 at 6:29 PM
That is really bad.I will have to modify the effect and maybe remove the light attenuation to make sure it is supported on more video cards. Or maybe I can set the default technique to use only one light source.
Jul 16, 2008 at 7:04 PM
I too am getting the error at modelMesh.Draw() for all samples with my ATI graphics card.  I am writing a tutorial using Blender, XNA, and your animation library.  Looks like I'll have to wait till you to have an ATI fix..  Looking forward to your release!
Jul 16, 2008 at 8:16 PM
I've just uploaded the BETA2 which correct problems on ATI video cards and is fully compatible with Xbox 360.
Jul 16, 2008 at 10:55 PM
Awesome, thanks for the fast reply.  I'm glad to report back that everything works perfectly.  Thank you.
Jul 21, 2008 at 8:02 AM
Edited Jul 22, 2008 at 9:26 AM
Hi Bruno,
I've got the message "Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed." on my Radeon 9200SE card.
This card supports only PS_1_4, VS_1_1. Is it posible to modify shader code (SkinnedModelEffect.fx) to make your library work with such old cards?
Jul 21, 2008 at 4:52 PM
Hi. It is possible to rewrite the SkinnedModelEffect for VS 1.1 and PS 1.4, however it will impose a lot of restrictions, such as very small skeletons, one light source, and others. That's why I decided that Shader Model 2 would be the minimum requirement for the XNAnimation.  Anyway, you can modify the default skinned effect and try to make it compatible with lower shaders profiles.