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,
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
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