MOGRE ; SetWorldGeometry ; terrain.cfg --> Access Violati

ChrisTTian667

17-09-2007 19:54:05

Hello Guys,

i started programming with MOGRE. I did the Ogre Tutorials well, and now, i wants to use it without the MogreFramework.dll.

But this results in an AccessViolation, when trying to load the terrain.cfg
in this line


mgr.SetWorldGeometry("C:\\ogresdk\\media\\terrain.cfg");


I am using VS 2005 Team Edition and it's saying: "Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist."

Its German, but means, that its trying to read/write to protected memory. Which is often a hint, that memory is defect. (Sorry, for my bad english!!)

Can someone give my at least a hint, what i am doing wrong?

cheers,
Christian


I post the complete Source here:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

using Mogre;

namespace MogreVsODE
{
static class Program
{
[STAThread]
static void Main()
{
try
{
OgreMain myOgreMain = new OgreMain();
myOgreMain.Init();
myOgreMain.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription, "An Ogre exception has occurred!");
else
throw;
}
}
}

public class OgreMain
{
private Root OgreRoot;
private RenderWindow OgreRenderWindow;

public OgreMain()
{

}

public void Init()
{
// Create root object
OgreRoot = new Root();

// Define Resources
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}

// Setup RenderSystem
RenderSystem rs = OgreRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
OgreRoot.RenderSystem = rs;
rs.SetConfigOption("Full Screen", "no");
rs.SetConfigOption("Video Mode", "640 x 480 @ 32-bit colour");

// Create Render Window
OgreRoot.Initialise(true, "Main Ogre Window");

// Init resources
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

// Create a Simple Scene
SceneManager mgr = OgreRoot.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);

Camera cam = mgr.CreateCamera("Camera");
cam.AutoAspectRatio = true;

if (File.Exists("C:\\ogresdk\\media\\terrain.cfg"))
{
mgr.SetWorldGeometry("C:\\ogresdk\\media\\terrain.cfg");
}

mgr.SetSkyDome(true, "Examples/CloudySky", 5, 8);

OgreRenderWindow = OgreRoot.AutoCreatedWindow;
OgreRenderWindow.AddViewport(cam);

Entity ent = mgr.CreateEntity("ninja", "ninja.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.LookAt(ent.BoundingBox.Center);
}

public void Go()
{
while (OgreRoot != null && OgreRoot.RenderOneFrame())
Application.DoEvents();
}
}

terrachild

27-09-2007 12:27:16

I'm having the same problem. I can't find anyone trying to solve this.

Sweenie

28-09-2007 08:01:14

Try creating the terrain after you have created the viewport.
To render the terrain Ogre needs a camera to calculate the errormetrics and I guess it uses the viewport to fetch the used camera.

Also make sure the heightmap image is found.

terrachild

29-09-2007 11:32:55

I created the terrain after the viewport and after reading in the resource config file.

Sure enough, it works fine.

Thanks very much.

Now, how do I add a collsion response to the camera like the demo had?

Also, the terrain seems to warp a little more when you move the camera than the demo did, is there some setting to adjust, perhaps LOD that will stop it from warping.

Thanks