AccessViolationException was unhandled!

Lawlcat

13-11-2010 23:11:48

I hate to make another topic so soon, but I'm running into a snag, not sure what's causing it.

Here's the code snippit,

string path = "levels/main.lvl";
ushort width = 0;
ushort height = 0;
ushort depth = 0;
byte[] blocks;
FileStream fs = File.OpenRead(path);
try
{
GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
byte[] ver = new byte[2];
gs.Read(ver, 0, ver.Length);
ushort version = BitConverter.ToUInt16(ver, 0);
if (version == 1874)
{
byte[] header = new byte[16]; gs.Read(header, 0, header.Length);
width = BitConverter.ToUInt16(header, 0);
height = BitConverter.ToUInt16(header, 2);
depth = BitConverter.ToUInt16(header, 4);
}
else
{
byte[] header = new byte[12]; gs.Read(header, 0, header.Length);
width = version;
height = BitConverter.ToUInt16(header, 0);
depth = BitConverter.ToUInt16(header, 2);
}

blocks = new byte[width * height * depth];
gs.Read(blocks, 0, blocks.Length);
gs.Close();
}
catch {}
SceneManager workManager = OgreForm.mRoot.GetSceneManager("manager");
try
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
for (int z = 0; z < depth; z++)
{
Entity ent = workManager.CreateEntity(x.ToString().PadLeft(5, '0') + "" + y.ToString().PadLeft(5, '0') + "" + z.ToString().PadLeft(5, '0'), "cube.mesh");
SceneNode node = workManager.RootSceneNode.CreateChildSceneNode(x.ToString().PadLeft(5, '0') + "" + y.ToString().PadLeft(5, '0') + "" + z.ToString().PadLeft(5, '0'), new Vector3(0, 0, 0));
node.AttachObject(ent);
node.Scale(new Vector3(20, 20, 20));
node.Position = new Vector3((ent.BoundingBox.Size.x * 19) * x, (ent.BoundingBox.Size.y * 19) * y, (ent.BoundingBox.Size.z * 19) * z);
}
}
}
}
catch { }


Basically, it gets a file called main.lvl and reads the file to get the width/depth and height of that, storing it as a ushort.

That works great, variables get storied properly to the correct size.

However on execution, I get an AccessViolationException was unhandled in line "Entity ent = workManager.CreateEntity(x.ToString().PadLeft(5, '0') + "" + y.ToString().PadLeft(5, '0') + "" + z.ToString().PadLeft(5, '0'), "cube.mesh");".

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Mogre.SceneManager.CreateEntity(String entityName, String meshName)
at MCLawl_Client.Client.LoadMap() in C:\Coding Projects\MCLClient\MCLawl_Client\Client.cs:line 62
at MCLawl_Client.OgreForm.button1_Click_1(Object sender, EventArgs e) in C:\Coding Projects\MCLClient\MCLawl_Client\OgreForm.cs:line 109

Anyone have any ideas?

In this case, Width is 256, Depth is 256 and Height is 64, which should be needing to create 4,194,304 entities and scenenodes.

Is that too much for Ogre? Cause this is about the minimal amount I will need for my project

As a side test, this works great when I tested a file who's width/depth/height were 16. Did exactly what I wanted it to

mstoyke

14-11-2010 02:37:29

I hate to make another topic so soon, but I'm running into a snag, not sure what's causing it.

Here's the code snippit,

--- snip ---

Basically, it gets a file called main.lvl and reads the file to get the width/depth and height of that, storing it as a ushort.

That works great, variables get storied properly to the correct size.

However on execution, I get an AccessViolationException was unhandled in line "Entity ent = workManager.CreateEntity(x.ToString().PadLeft(5, '0') + "" + y.ToString().PadLeft(5, '0') + "" + z.ToString().PadLeft(5, '0'), "cube.mesh");".

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Mogre.SceneManager.CreateEntity(String entityName, String meshName)
at MCLawl_Client.Client.LoadMap() in C:\Coding Projects\MCLClient\MCLawl_Client\Client.cs:line 62
at MCLawl_Client.OgreForm.button1_Click_1(Object sender, EventArgs e) in C:\Coding Projects\MCLClient\MCLawl_Client\OgreForm.cs:line 109

Anyone have any ideas?

In this case, Width is 256, Depth is 256 and Height is 64, which should be needing to create 4,194,304 entities and scenenodes.

Is that too much for Ogre? Cause this is about the minimal amount I will need for my project

As a side test, this works great when I tested a file who's width/depth/height were 16. Did exactly what I wanted it to


I think it's not a good idea to create millions of scenenodes and entities with Ogre (or Mogre in this case), you should expect to see a high spf (seconds per frame) with this. I assume I see code of another minecraft clone here? ;)

This kind of exception can be caused by Ogre and it's hard to say if the problem is located in Ogre or the Mogre wrapper. If you can provide some more details about the kind of scene you want to create I might be able to give you some ideas how to optimize the scene to use less resources.

Lawlcat

14-11-2010 03:34:53

You could say it's a minecraft clone, it's going for the same functionality.

Basically it's going to be a custom client to be used with the MCLawl creative server software that I write. I need a way to parse the .lvl data and draw all the blocks so that they can be interacted with and such.

I'm THINKING I'm going to have to find some way to draw only ones visible by the camera, and not anything else.

mstoyke

14-11-2010 17:31:24

You might want to look at this: http://www.ogre3d.org/forums/viewtopic. ... =minecraft

Lawlcat

14-11-2010 21:56:41

Awesome, thanks mstoyke. Voxel stuff is well beyond me, blows my mind and hard to find any documentation or tutorials on it, but it gives me a place to look :) Thanks again!