Access violation when using Viewport (Mogre 1.6.2)

Thomas233

04-10-2009 15:54:33

Hi,

i`m getting a lot of access violations at runtime under certain circumstances. I`m initializing the engine as described in the Mogre/Ogre tutorials but when using i Viewport i`m getting an acess violation after rendering is started. Here`s some code:


public partial class BaseEngine
{
public RenderTarget RootRenderTarget
{
//get { return Root.Singleton.AutoCreatedWindow; }
get; set;
}

public List<AttachableComponent> RenderComponents
{
get { return components; }
}

public SceneManager SceneManager
{
get; set;
}

public Camera MainCamera
{
//get { return this.SceneManager.GetCamera(EngineConfig.DefaultCameraName); }
get; set;
}

public Viewport MainViewPort
{
//get { return this.RootRenderTarget.GetViewport(0); }
get; set;
}

protected void StartupEngine(RenderConfiguration config)
{
InitCredentials(config);
InitConfig();

RootRenderTarget = Root.Singleton.Initialise(true);

InitListeners();
InitInput();
InitScene();
InitView();
}

protected void InitCredentials(RenderConfiguration config)
{
new Root();

RenderSystem renderSystem = null;
foreach (RenderSystem rs in Root.Singleton.GetAvailableRenderers())
{
if (config.RenderSystem.Equals(rs.Name))
renderSystem = rs;
}

if (renderSystem == null)
throw new GameEngineInitializationError("Rendering subsystem not found: " + config.RenderSystem);

Root.Singleton.RenderSystem = renderSystem; //default: DirectX 9

Root.Singleton.RenderSystem.SetConfigOption("Full Screen", config.FullScreen.ToString()); //default: false
Root.Singleton.RenderSystem.SetConfigOption("Video Mode", String.Format("{0} x {1} @ {2}-bit colour", new object[] { config.ResolutionWidth, config.ResolutionHeight, config.BitDepth })); //default: 640x480@32
}

protected void InitInput()
{
//
}

protected void InitScene()
{
SceneManager = Root.Singleton.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE,EngineConfig.DefaultSceneManagerName);
SceneManager.AmbientLight = new ColourValue(0, 0, 0);
}

protected void InitConfig()
{
ConfigFile configFile = new ConfigFile();
configFile.Load(EngineConfig.ResourcesConfigFile, "\t:=", true);

LoadResourcesConfig(EngineConfig.ResourcesConfigFile); // adds resource locations
}

protected void InitView()
{
MainCamera= SceneManager.CreateCamera(EngineConfig.DefaultCameraName);
MainCamera.Position = new Vector3(EngineConfig.CameraStartPosX, EngineConfig.CameraStartPosY, EngineConfig.CameraStartPosZ);
MainCamera.LookAt(new Vector3(EngineConfig.CameraStartPosX + 1, EngineConfig.CameraStartPosY - 1, EngineConfig.CameraStartPosZ + 1));

// Access violation if Viewport gets intialized !!!
MainViewPort = RootRenderTarget.AddViewport(MainCamera);
MainViewPort.BackgroundColour = new ColourValue(1, 1, 1);
MainCamera.AspectRatio = ((float)MainViewPort.ActualWidth) / ((float)MainViewPort.ActualHeight);
}

protected void InitListeners()
{
Root.Singleton.FrameStarted += FrameStarted;
}

public void StartRendering()
{
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

Root.Singleton.StartRendering(); //access violation here !!!
}
}


First BaseEngine.StartupEngine() is called (using a default render configuration). Then BaseEngine.StartRendering() gets called and about 2-3 seconds after the window is rendered I get an access violation (where the inner exception is NULL). I only get this if I initialize a viewport (look at InitView()). If only a camera is initialized the window is rendered properly without any exception.

I`m using latest Mogre 1.6.2 binaries (debug) from this forum and Visual Studio 2008 SP2 (C++, C# etc.).

Anyone has an idea what`s wrong here ?

Thanks !

Thomas

Thomas233

14-10-2009 19:29:25

No one? So my code is ok ?

I`ve now switched to latest 1.6.4 binaries, but it also doesn`t work.

Btw what about MOIS, do i need to reference it in 1.6.4 (isn`t it embedded in Mogre.dll) ?

nataz

14-10-2009 21:19:09

I dont see you calling Root.Initialize nor the Window Creation at all.

Look at this:


mRoot = new Root();
mRoot.FrameEnded += new FrameListener.FrameEndedHandler(mRoot_FrameEnded);
LogManager.Singleton.DefaultLog.MessageLogged += new LogListener.MessageLoggedHandler(DefaultLog_MessageLogged);
InitializeBasics(true);

mRoot.LoadPlugin("RenderSystem_Direct3D9.dll");
//mRoot.FrameEnded += new FrameListener.FrameEndedHandler(root_FrameEnded);
mRoot.RenderSystem = GetRenderSystem("Direct3D9 Rendering Subsystem");
mRoot.RenderSystem.SetConfigOption("Allow NVPerfHUD", "No");//"Yes"
mRoot.RenderSystem.SetConfigOption("Anti aliasing", "None");//
mRoot.RenderSystem.SetConfigOption("Floating-point mode", "Fastest");//Consistant
mRoot.RenderSystem.SetConfigOption("Full Screen", "No");
mRoot.RenderSystem.SetConfigOption("VSync", "No");//"Yes"
mRoot.RenderSystem.SetConfigOption("Video Mode", string.Format("{0} x (1) @ 32-bit colour", Width, Height));
RenderParams = new NameValuePairList();

RenderParams["externalWindowHandle"] = RenderControlHandle.ToString();
mRoot.Initialise(false);
if (createStandardWindow)
{
RenderWindow = mRoot.CreateRenderWindow("rootWindow", (uint)Width, (uint)Height, false, RenderParams);
SceneManager = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
Camera = SceneManager.CreateCamera("default");
Viewport = RenderWindow.AddViewport(Camera);
Viewport.BackgroundColour = ColourValue.Black;
Camera.AspectRatio = Viewport.ActualWidth / Viewport.ActualHeight;
InputManager.Instance.Initialize(mRoot, SceneManager, Camera);
}

Thomas233

14-10-2009 21:58:29

Ah sorry i forgot to post another piece of my code (where the engine gets initialized at all):


protected void StartupEngine(RenderConfiguration config)
{
InitCredentials(config);
InitConfig();

RootRenderTarget = Root.Singleton.Initialise(true);

InitListeners();
InitInput();
InitScene();
InitView();
}

GantZ

14-10-2009 22:55:37

my guess here is that the Root object you create with new Root() when calling InitCredentials get garbage collected later on, destroying the underlying native objects. keep a reference to root directly in your csharp project rather than rely on Root.Singleton. (it's different for other singleton, since theirs natives objects are all destroyed in the root destructor).

Thomas233

15-10-2009 18:43:24

Hi Gantz,
my guess here is that the Root object you create with new Root() when calling InitCredentials get garbage collected later on, destroying the underlying native objects. keep a reference to root directly in your csharp project rather than rely on Root.Singleton. (it's different for other singleton, since theirs natives objects are all destroyed in the root destructor).

Wah, I get crazy. That also doesn`t help. After adding a new property to my main engine class where a reference to Root.Singleton is stored, the same error occurs again.
MogreRoot = new Root();
MogreRoot.RenderSystem = renderSystem;

// etc.


I really have no idea what`s wrong here. Btw. the inner execption is
" at Ogre.Root.startRendering(Root* )\r\n at Mogre.Root.StartRendering()\r\n at TNT.Gaming.Engine.BaseEngine.StartRendering() at D:\\Dev\\DotNet\\WeirdHospital\\TnT.Gaming.Engine\\BaseEngine.cs:Zeile 71.\r\n

Thanks a lot for providing the latest 1.6.4 binaries GantZ, I would really like to see the Mogre project going on until I can use it (which I really would like to do !!) ;-)

Thomas

nataz

15-10-2009 18:47:12

AHA! You are german! Wohoo /me is not the only one

GantZ

15-10-2009 19:51:18

i have investigate a little in your code, and when copy pasting it and make it run (i have just remove the InitConfig part), i haven't run into any exception. could you check if you use the correct DLL ? since you basically get a segfault error, it could be that some of the DLL you use are not the good one.

also, about the MOIS.dll, you could use the one provided with the 1.6.2 version, it work ok with this one.

Thomas233

15-10-2009 19:52:13

Hi nataz,

AHA! You are german! Wohoo /me is not the only one
Let me guess, the exception text exposed me ? :lol:

German only (nothing important): Naja, ich glaub das du/wir sicher nicht die einzigen deutschsprachigen hier sind.... ;-)

Thomas

Thomas233

15-10-2009 20:18:10

No chance ! I tried everything !

I downloaded the latest 1.6.2 binaries, extracted them into a temporary folder. Then i downloaded the 1.6.4 binaries and extracted them into the same directory (overwriting the old ones). After that I removed all references in my solution and re-added the references to Mogre_d and MOIS if needed. Finally i put the code provided here into a new class, initialized a new instance and started rendering.
But the same exception is raised again and again and again ! I really don`t know what`s wrong here.

Btw. i`m using Windows 7 RC may that be a problem (running VS 2008 latest SP and latest DirectX runtime) ?

Thanks !

Thomas

GantZ

15-10-2009 20:26:07

i`m using Windows 7 RC

I don't know if anyone have already test Mogre under windows 7, could you see if your code work on an other OS ? or you could post your test app here so i could test it ?(i use windows xp sp3)

Thomas233

15-10-2009 22:37:12

Ok, here is a full sample project (16 Mb):

http://www.file-upload.net/download-194 ... p.rar.html

Don`t forget to copy all files from the "lib" directory to your output directory.

Thank you a lot !

smiley80

15-10-2009 23:07:54

Nothing wrong with your code.

Delete the Plugin_PCZSceneManager* dlls and remove the entry from plugins.cfg.
The Portal Connected Zone Scene Manager doesn't work with Mogre.

GantZ

15-10-2009 23:23:11

that's what i was going to write.. until you do :)

(note to myself, don't add it in further release until it work :oops: )

Thomas233

16-10-2009 17:03:34

Thank you very much ! That`s it.

:mrgreen: :mrgreen: :mrgreen:

luismesas

16-10-2009 23:59:32

i`m using Windows 7 RC

I don't know if anyone have already test Mogre under windows 7, could you see if your code work on an other OS ? or you could post your test app here so i could test it ?(i use windows xp sp3)


I have tested it on followingo S.O.

Windows 7 Beta 32 bits
Windows 7 RC 32 bits
Windows Vista Home Premium 32 bits
Windows Vista Home Premium 64 bits
Windows XP Pro SP3

It works ok on all them.