3

I've started learning XNA 4.0 and I'm trying to load and draw a 3D model, converted from 3ds to fbx/x using Blender 2.6 . The program gives no build errors or warnings and I've been able to open the executable few times and it worked fine. After some time I couldn't open the game anymore and it started giving me this error:

AccessViolationException - Attempted to read or write protected memory. This is often an indication that other memory has been corrupted

I sent the project to a friend and he was able to compile & run the game.

Removing mesh.Draw() part seems to solve this but I need to display the model.

//Later edit: I found out that the error is temporarily, so if it gives the error now, after some time (or reopening visual studio, I don't know yet which one triggers this) I can run the program normally using the same source code and files.

The StackTrace:

System.AccessViolationException was unhandled Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=Microsoft.Xna.Framework.Graphics
StackTrace: at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present(tagRECT* pSource, tagRECT* pDest, HWND__* hOverride) at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present() at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.EndDraw() at Microsoft.Xna.Framework.Game.EndDraw() at Microsoft.Xna.Framework.Game.DrawFrame() at Microsoft.Xna.Framework.Game.Tick() at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e) at Microsoft.Xna.Framework.GameHost.OnIdle() at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame() at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e) at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr 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.RunGame(Boolean useBlockingRun) at Microsoft.Xna.Framework.Game.Run() at _3D.Program.Main(String[] args) in C:\Users\username\Desktop\3D\3D\3D\Program.cs:line 15
InnerException:

Thanks in advance and sorry for my bad english.

Apex
  • 43
  • 6
  • 1
    Make sure you have the latest drivers for your graphics card and the latest version of DirectX on your machine. It may be possible that there are some shaders your GFX card don't support. If so, try removing any shaders you've added to the model. – keyboardP Jan 01 '12 at 19:46
  • I think it may be bug or something wrong with your code. Not sure exactly but it seems that when you're running the program after every exit the allocated memory for your 3d file would not be set to free. But it just a 3d model with a little memory consumption I'm not sure with my speech. I never faced this error in these 2 years that I'm working with XNA. – MahanGM Jan 01 '12 at 19:48
  • I'm not sure if it is from my video card, because I was able to run the application and see the model, the error appeared after I opened and closed it several times (debugging). And...about the memory, I really don't know - shouldn't the program clean the memory used after it's closed ? – Apex Jan 01 '12 at 19:56
  • Right click on the solution and select `Clean`. Then right click and `Rebuild`. Maybe it's a temporary file causing the problem. – keyboardP Jan 01 '12 at 20:00
  • @keyboardP I've tried, but it doesn't help - I still get the error. – Apex Jan 01 '12 at 20:08
  • What's the code around the method call? – annonymously Jan 01 '12 at 21:40
  • @annonymously I've posted the code of the application [here](http://pastebin.com/pYYE5UG3) – Apex Jan 01 '12 at 22:18
  • @Hadden The code looks ok, so I think it's something specific to your computer – annonymously Jan 01 '12 at 22:30
  • @annonymously I really don't know... If my computer had a problem then the program should've never ran, but it sometimes can be opened, after reopening visual studio or waiting some time, I don't know yet which one "fixes" this. – Apex Jan 01 '12 at 22:38
  • 1
    @Hadden This is starting to sound a bit like [Jenine](http://stackoverflow.com/questions/2193953/flash-cs4-refuses-to-let-go) but I didn't think VS was like that. – annonymously Jan 01 '12 at 22:40
  • I have this all the time outside of XNA and it seems to be a bug in VS.net which does not handle large projects and/or memory allocation successfully. My only solution is to exit VS.net and reopen in, clean and rebuild. I can't be more helpful, but I dont think its exclusively an XNA thing. – PhillipH Jul 07 '14 at 21:22

0 Answers0