# Mesh Intersect throwing AccssViolationException?

## Recommended Posts

homer_3    173
I'm trying to test if a ray intersects with a mesh and when I do
box.Intersect(_camera.Position, new Vector3(1, 0, 0),out info);


I get an AccessViolationException error, at run time, that says I'm attempting to read or write to protected memory. box was created using Mesh.Box(). Can anyone shed some light on why I'd be getting this error?

##### Share on other sites
Evil Steve    2017
I'd guess that creating the box failed. Is there anything interesting from the Debug Runtimes?

##### Share on other sites
homer_3    173
Before I tried testing for the intersect I drew the box on screen and it showed up fine. I'll check the link though and see what I can find.

##### Share on other sites
Evil Steve    2017
What details do you get with the access violation (I don't know about C#, but in C++ you get a message like "Access violation (0xC0000005) reading location 0x00000000")? Another alternative is that _camera isn't a valid object.

##### Share on other sites
homer_3    173
I found the issue. It didn't like where I was calling intersect. box must not have been fully initialized even though I put it in an if statement that checked to make sure box wasn't null. I tried checking for an intersect immediately after doing mesh = Mesh.Box() and got no error.