Access violation???

grizzley90

24-10-2006 00:01:15

:?

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="Mogre"
StackTrace:
at std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{ctor}(basic_string<char\,std::char_traits<char>\,std::allocator<char> >* , SByte* )
at Mogre.RenderSystem.SetConfigOption(String name, String value)
at GameEngine.Internal.GraphicsManager.Configure() in C:\Documents and Settings\Administrator\My Documents\GameEngine\020\ GameEngine\Managers\GraphicsManager.cs:line 226

It fails here:
mRoot.RenderSystem.SetConfigOption("Video Mode", "800 x 600 @ 16-bit colour"/*mCurrentConfiguration.VideoMode*/);


Im absolutely clueless... maybe i have an older mogre or is this set config option not available anymore??

Bekas

24-10-2006 09:02:08

I can't reproduce it. Use the latest version and if the problem persists post a small example that isolates the problem.

Clay

24-10-2006 14:21:53

Does Ogre.Log have any errors or exceptions in there? Paste it in this thread.

grizzley90

25-10-2006 20:24:41

the ogre log didn't show anything usefull.... neither did using the latest version of mogre. I am using SetConfigOption for a whole bunch of other settings as well and not just the video mode. What solved the problem was moving the SetConfigOption to the top of the set config option list so that the first option i set was the video mode. That solved it .. im guessing that this is an ogre limitation but im not sure.... it is now failing at SetConfigOption("VSync", ....) so i commented that out since i dont know where its supposed to go... It still gives me an accessviolation exception error when i uncomment the vsync set config option................. :(

grizzley90

25-10-2006 22:20:47

Ahhh problem solved it turns infact the configuration object that i was using didn't have anything for vsync so i was sending a null/empty vector.... :oops: :oops: :oops: problem solved... here is my graphics manager if anyone cares to spot mistakes.

It is still a work in progress.......


/*
-----------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
-----------------------------------------------------------------------------
*/

using System;

namespace GameEngine.Internal
{
/// <summary>
/// This class creates the graphics and controls ogre. It also deals with the various graphics subsystems.
/// </summary>
sealed internal class GraphicsManager
{
#region Values
private Mogre.Root mRoot;
private bool mReady = false;
private Mogre.RenderWindow mWindow;
private Config.Config mCurrentConfiguration;
private Mogre.SceneManager mSceneManager;
private Mogre.Overlay debugOverlay;
#endregion Values

#region Properties
/// <summary>
/// Gets the root.
/// </summary>
/// <value>The root.</value>
public Mogre.Root Root
{
get
{
return mRoot;
}
}
/// <summary>
/// Gets the window.
/// </summary>
/// <value>The window.</value>
public Mogre.RenderWindow Window
{
get
{
return mWindow;
}
}
/// <summary>
/// Gets a value indicating whether this <see cref="GraphicsManager"/> is ready.
/// </summary>
/// <value><c>true</c> if ready; otherwise, <c>false</c>.</value>
public bool Ready
{
get
{
return mReady;
}
}
/// <summary>
/// Gets the scene manager.
/// </summary>
/// <value>The scene manager.</value>
public Mogre.SceneManager SceneManager
{
get
{
return mSceneManager;
}
}
#endregion Properties

#region Methods
/// <summary>
/// Destroys Ogre.
/// </summary>
public void Dispose()
{
Mogre.ResourceGroupManager.Singleton.ShutdownAll();
mWindow.Destroy();
if(mWindow != null){
mWindow.Dispose();
mWindow = null;
}
mRoot.Dispose();
mReady = false;
}
/// <summary>
/// Starts the rendering.
/// </summary>
public void StartRendering()
{
if(mReady==true)
mRoot.StartRendering();
}
/// <summary>
/// Initializes the specified this state.
/// </summary>
/// <param name="ThisState">State of the this.</param>
/// <returns></returns>
public bool Initialize(GameEngine.Config.Config Configuration)
{
try
{
mCurrentConfiguration = Configuration;
mRoot = new Mogre.Root("Plugins.cfg","","Graphics.log");
Mogre.LogManager.Singleton.LogMessage("Ogre Root Created.");
if (!LoadandConfigureRenderSystems())
{
Mogre.LogManager.Singleton.LogMessage("Failed to load RenderSystem or configure render systems.");
return false;
}
if (!SetupCoreResources())
{
Mogre.LogManager.Singleton.LogMessage("Could not setup core resources.");
return false;
}
if (!LoadSceneManager())
{
Mogre.LogManager.Singleton.LogMessage("Could not load the specified scene manager.");
return false;
}
if (!LoadExtraPlugins())
{
Mogre.LogManager.Singleton.LogMessage("Could not load the extra plugins.");
return false;
}
ShowDebugOverlay();
Mogre.TextureManager.Singleton.DefaultNumMipmaps = 5;
mReady = true;
return true;
}
catch (Exception e)
{
throw new GameEngine.Exception(e.Message + ". Could not create graphics.");
}
}
private bool LoadandConfigureRenderSystems()
{
Mogre.RenderSystemList list = mRoot.GetAvailableRenderers();
bool foundit = false;
Mogre.RenderSystem selectedRenderSystem = null;
foreach (Mogre.RenderSystem rs in mRoot.GetAvailableRenderers())
{
selectedRenderSystem = rs;
if ((mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.DirectX) && (selectedRenderSystem.Name == "Direct3D9 Rendering Subsystem"))
{
foundit = true;
break;
}
else if ((mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.OpenGL) && (selectedRenderSystem.Name == "OpenGL Rendering Subsystem"))
{
foundit = true;
break;
}
}
if (!foundit)
{
if (mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.DirectX)
{
mRoot.LoadPlugin("RenderSystem_Direct3D9.dll");
foreach (Mogre.RenderSystem rs in mRoot.GetAvailableRenderers())
{
selectedRenderSystem = rs;
if (selectedRenderSystem.Name == "Direct3D9 Rendering Subsystem")
{
break;
}
}
}
else if (mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.OpenGL)
{
mRoot.LoadPlugin("RenderSystem_GL.dll");
foreach (Mogre.RenderSystem rs in mRoot.GetAvailableRenderers())
{
selectedRenderSystem = rs;
if (selectedRenderSystem.Name == "OpenGL Rendering Subsystem")
{
break;
}
}
}
else
return false;
}

mRoot.RenderSystem = selectedRenderSystem;
if (mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.DirectX)
{
mRoot.RenderSystem.SetConfigOption("Video Mode", mCurrentConfiguration.VideoMode);
mRoot.RenderSystem.SetConfigOption("VSync", mCurrentConfiguration.VSync);
mRoot.RenderSystem.SetConfigOption("Allow NVPerfHUD", mCurrentConfiguration.NVPerfHUD);
mRoot.RenderSystem.SetConfigOption("Anti aliasing", mCurrentConfiguration.AntiAliasing);
mRoot.RenderSystem.SetConfigOption("Floating-point mode", mCurrentConfiguration.FloatingPointMode);
mRoot.RenderSystem.SetConfigOption("Full Screen", mCurrentConfiguration.FullScreen);
}
else if (mCurrentConfiguration.GraphicsAPI == GameEngine.Config.GraphicAPI.OpenGL)
{
mRoot.RenderSystem.SetConfigOption("Full Screen", mCurrentConfiguration.FullScreen);
mRoot.RenderSystem.SetConfigOption("Video Mode", mCurrentConfiguration.VideoMode);
mRoot.RenderSystem.SetConfigOption("Colour Depth", mCurrentConfiguration.ColourDepthGL);
mRoot.RenderSystem.SetConfigOption("Display Frequency", mCurrentConfiguration.DisplayFrequencyGL);
mRoot.RenderSystem.SetConfigOption("FSAA", mCurrentConfiguration.FSAAGL);
mRoot.RenderSystem.SetConfigOption("VSync", mCurrentConfiguration.VSync);
mRoot.RenderSystem.SetConfigOption("RTT Preferred Mode", mCurrentConfiguration.RTTModeGL);
}
if (mCurrentConfiguration.AutoCreateWindow == true)
{
try
{
mWindow = mRoot.Initialise(true, mCurrentConfiguration.ApplicationWindowName);
}
catch (Exception)
{
return false;
}
}
else
{
try
{
mWindow = mRoot.Initialise(false, mCurrentConfiguration.ApplicationWindowName);
Mogre.NameValuePairList vplist = new Mogre.NameValuePairList();
// Pass the HWND handle of the .NET Form window to Ogre
vplist["externalWindowHandle"] = mCurrentConfiguration.WindowHandle.ToString();
vplist["left"] = mCurrentConfiguration.XPosition.ToString();
vplist["top"] = mCurrentConfiguration.YPosition.ToString();
mWindow = mRoot.CreateRenderWindow(mCurrentConfiguration.ApplicationWindowName,
mCurrentConfiguration.XSize,
mCurrentConfiguration.YSize,
false, vplist);
}
catch (Exception)
{
return false;
}
}
return true;
}
private bool SetupCoreResources()
{
try{
Mogre.ResourceGroupManager.Singleton.AddResourceLocation("Media/OgreCore.zip", "Zip", "Core");
Mogre.ResourceGroupManager.Singleton.InitialiseResourceGroup("Core");
}
catch(Exception)
{
return false;
}
return true;
}
private bool LoadExtraPlugins()
{
try{
mRoot.LoadPlugin("Plugin_ParticleFX.dll");
mRoot.LoadPlugin("Plugin_CgProgramManager.dll");
}
catch(Exception){
return false;
}
return true;
}
private bool LoadSceneManager()
{
if (mCurrentConfiguration.SceneManager == "ST_GENERIC (OctreeSceneManager)")
{
mRoot.LoadPlugin("Plugin_OctreeSceneManager.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_GENERIC);
return true;
}
else if (mCurrentConfiguration.SceneManager == "ST_EXTERIOR_CLOSE (TerrainSceneManager)")
{
mRoot.LoadPlugin("Plugin_TerrainSceneManager.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_EXTERIOR_CLOSE);
return true;
}
else if (mCurrentConfiguration.SceneManager == "ST_EXTERIOR_FAR (NatureSceneManager)")
{
mRoot.LoadPlugin("Plugin_NatureSceneManager.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_EXTERIOR_FAR);
return true;
}
else if (mCurrentConfiguration.SceneManager == "ST_EXTERIOR_REAL_FAR (PagingLandScapeSceneManager2)")
{
mRoot.LoadPlugin("Plugin_PLSM2.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_EXTERIOR_REAL_FAR);
return true;
}
else if (mCurrentConfiguration.SceneManager == "ST_INTERIOR (BSPSceneManager)")
{
mRoot.LoadPlugin("Plugin_BSPSceneManager.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_INTERIOR);
return true;
}
else if (mCurrentConfiguration.SceneManager == "ST_GENERIC (DotSceneManager)")
{
mRoot.LoadPlugin("Plugin_DotSceneManager.dll");
mSceneManager = mRoot.CreateSceneManager(Mogre.SceneType.ST_GENERIC);
return true;
}
else
return false;
}

private void ShowDebugOverlay()
{
if (mCurrentConfiguration.ShowFrameRate == true)
{
debugOverlay = Mogre.OverlayManager.Singleton.GetByName("Core/DebugOverlay");
debugOverlay.Show();
mRoot.FrameStarted += new Mogre.FrameListener.FrameStartedHandler(UpdateStats);
}
}
private bool UpdateStats(Mogre.FrameEvent evt)
{
if (mWindow.IsClosed)
return false;
string currFps = "Current FPS: ";
string avgFps = "Average FPS: ";
string bestFps = "Best FPS: ";
string worstFps = "Worst FPS: ";
string tris = "Triangle Count: ";

// update stats when necessary
try
{
Mogre.OverlayElement guiAvg = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/AverageFps");
Mogre.OverlayElement guiCurr = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/CurrFps");
Mogre.OverlayElement guiBest = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/BestFps");
Mogre.OverlayElement guiWorst = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/WorstFps");

Mogre.RenderTarget.FrameStats stats = mWindow.GetStatistics();

guiAvg.Caption = avgFps + stats.AvgFPS;
guiCurr.Caption = currFps + stats.LastFPS;
guiBest.Caption = bestFps + stats.BestFPS + " " + stats.BestFrameTime + " ms";
guiWorst.Caption = worstFps + stats.WorstFPS + " " + stats.WorstFrameTime + " ms";

Mogre.OverlayElement guiTris = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/NumTris");
guiTris.Caption = tris + stats.TriangleCount;

Mogre.OverlayElement guiDbg = Mogre.OverlayManager.Singleton.GetOverlayElement("Core/DebugText");
guiDbg.Caption = mWindow.DebugText;
}
catch
{
return false;
}
return true;
}
#endregion Methods
}
}

Bekas

25-10-2006 22:55:55

Heh, I think this qualifies as a Mogre problem :). I'll add a check that throws null reference exception if the .NET string is null, before converting it to an Ogre string.