I'm trying to design a simple button that toggles wireframe mode on a Mesh. So I tried the following code. (I am using the DXUT framework)
private void OnWireClicked(object sender, EventArgs e){
if ((int)(sampleFramework.Device.RenderState.FillMode) != 3)sampleFramework.Device.RenderState.FillMode =
FillMode.Solid; elsesampleFramework.Device.RenderState.FillMode =
FillMode.WireFrame;}
I don't see what is wrong with this but it gives the following error at runtime
System.InvalidOperationException was unhandled
Message="Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.BeginInvoke(Delegate method)
at Microsoft.Samples.DirectX.UtilityToolkit.Framework.Dispose() in C:\Documents and Settings\Colin Browne\My Documents\Visual Studio 2005\Projects\DirectXApplication\DirectXApplication\Common\dxmut.cs:line 3973
at EmptyProjectSample.EmptyProject.Main() in C:\Documents and Settings\Colin Browne\My Documents\Visual Studio 2005\Projects\DirectXApplication\DirectXApplication\EmptyProject.cs:line 511
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I really have no idea what all of this means and it doesn't help in anyway for me to fix what is wrong (well it doesn't help me at least!)
If I remove the if statement it doesn't crash but then obviously it doesn't toggle wireframe mode and solid mode which is what i want it to do. I don't understand why the program crashes at run time. Any idea on what I am doing wrong
EDIT: Now I'm REALLY confused. Below is code I wrote lifted DIRECTLY from another bit of source code, I simply changed the code so that it pointed to the correct device name. It worked perfectly in the old bit of code, but crashes in the DXUT...
private void OnWireClicked(object sender, EventArgs e){
if ((int)(sampleFramework.Device.RenderState.FillMode + 1) > 3)sampleFramework.Device.RenderState.FillMode =
FillMode.Point; elsesampleFramework.Device.RenderState.FillMode++;
}
What am i doing wrong why is perfectly legal working code not working in this project, but it works in another project

Run time error when attempting to toggle Wireframe mode.
Lucien de Rubempre
I didn't mean to imply the error didn't happen there, just that the exception you were getting was not the correct one.
I suspect you have a pure device and you cannot read back render states from a pure device. Either stop using a pure device or remember the current render state yourself.
ITAGraham
After changing the option as you suggested Zman the following.
Microsoft.DirectX.Direct3D.InvalidCallException occurred
if ((int)(sampleFramework.Device.RenderState.FillMode + 1) > 3)Message="Error in the application."
Source="Microsoft.DirectX.Direct3D"
ErrorCode=-2005530516
ErrorString="D3DERR_INVALIDCALL"
StackTrace:
at Microsoft.DirectX.Direct3D.Device.GetRenderStateInt32(RenderStates state)
at Microsoft.DirectX.Direct3D.RenderStateManager.get_FillMode()
at EmptyProjectSample.EmptyProject.OnWireClicked(Object sender, EventArgs e) in C:\Documents and Settings\Colin Browne\My Documents\Visual Studio 2005\Projects\DirectXApplication\DirectXApplication\EmptyProject.cs:line 442
The error does infact happen at that very line, as i suspected since if I take it away it works without a problem. As I said before this line worked perfectly in another set of tutorials i downloaded (just with sampleFramework.Device replaced by m_device or something like that)
If my above method is flawed for some reason could you explain why as well if possible and what I need to do instead to toggle the Fillmode value without this exception
----------------------------------------------
See here. This is very likely the same problem.
----------------------------------------------------------
I'm sorry I don't quite understand the connection between that problem and mine, maybe if you could explain it a bit more explicitly since I'm still relatively new to c# and windows programming.
alindblad
Thanks a lot, this was exactly the problem. I commented out the bit of code that created a pure device and it works as expected.
Read up a bit about pure devices and I guess I will always disable that feature since whatever performance boost it gives isn't of much consequence to me.
Thanks again for your reply.
tom__ro
In my experience this is becuase the framework is hiding the real error from you. When the framework tries to shutdown if everything is not disposed and closed properly you see things like this happening.
Turn on 'break on all exceptions' rather than the default of 'break on unhandled excpetions' in the Debug/Excpetions dialog. You will probably find that a different exception is happening at that line of code.
Wayne Godfrey