MOGRE bug on exit in OpenGL rendering system

pepote

25-05-2007 16:12:21

Whe you call return false on FrameEnded or FrameStarted listeners to exit program this run FINE in DirectX rendering system. But if you run the program in OpenGL this run an error message "memory violation access".

This happened on windows I din't try it on linux.

moviestar

31-08-2007 21:03:56

I get the same behaviour with a very simple project. PLEASE HELP!

while (mRoot != null && mRoot.RenderOneFrame())
System.Windows.Forms.Application.DoEvents(); <===== CRASH HERE WHEN CLOSING WINDOW


{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}


" at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)\r\n at System.Windows.Forms.Form.DefWndProc(Message& m)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n at System.Windows.Forms.Form.WmSysCommand(Message& m)\r\n at System.Windows.Forms.Form.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)\r\n at System.Windows.Forms.Form.DefWndProc(Message& m)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n at System.Windows.Forms.Form.WmNcButtonDown(Message& m)\r\n at System.Windows.Forms.Form.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.DoEvents()\r\n at MOGRETest.Viewer3D.Go(Boolean useOpenGL) in D:\\Documents and Settings\\hcharbon\\My Documents\\Visual Studio 2005\\Projects\\MOGRETest\\Viewer3D.cs:line 112\r\n at MOGRETest.Program.Main() in D:\\Documents and Settings\\hcharbon\\My Documents\\Visual Studio 2005\\Projects\\MOGRETest\\Program.cs:line 20\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"

pepote

03-09-2007 20:30:49

Try the same code in DirectX Mode. :(

moviestar

03-09-2007 20:35:56

The same code in DirectX works fine. But my app needs OpenGL. :(

KeldorKatarn

09-11-2007 15:52:36

Same problem is happening for me with the tutorial project of tutorial 5 "The Ogre startup sequence"

The application runs fine but if OpenGL is used it causes an access violation on program termination.

bleubleu

09-11-2007 18:36:50

Hi guys!

Rules of thumb to avoid these kind of crashes:

  1. Destroy and dispose of your ogre objects. Especially big thing likes render windows, scene managers, etc. Destroying the last render window will shut down the render system which is good for a clean exit.[/*:m]
  2. Dispose/nullify the root object.[/*:m]
  3. Dispose and/or nullify all *Ptr objects.[/*:m][/list:u]
    Here's the corrected Tutorial05. I basically added a Shutdown method that cleans up the render window an the root object.

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Mogre;
    using System.Drawing;

    namespace Tutorial05
    {
    static class Program
    {
    [STAThread]
    static void Main()
    {
    OgreStartup ogre = new OgreStartup();
    ogre.Go();
    }
    }

    class OgreStartup
    {
    Root mRoot = null;
    RenderWindow mWindow = null;

    float ticks = 0;

    public void Go()
    {
    CreateRoot();
    DefineResources();
    SetupRenderSystem();
    CreateRenderWindow();
    InitResources();
    CreateScene();
    StartRenderLoop();
    Shutdown();
    }

    void Shutdown()
    {
    mWindow.Destroy();
    mWindow.Dispose();
    mWindow = null;

    mRoot.Dispose();
    mRoot = null;
    }

    void CreateRoot()
    {
    mRoot = new Root();
    }

    void DefineResources()
    {
    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);
    }
    }
    }

    void SetupRenderSystem()
    {
    if (!mRoot.ShowConfigDialog())
    throw new Exception("The user canceled the configuration dialog.");

    //// Setting up the RenderSystem manually.
    //RenderSystem rs = mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
    //mRoot.RenderSystem = rs;
    //rs.SetConfigOption("Full Screen", "No");
    //rs.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
    }

    void CreateRenderWindow()
    {
    mWindow = mRoot.Initialise(true, "Main Ogre Window");

    //// Embedding ogre in a windows hWnd. The "handle" variable holds the hWnd.
    //NameValuePairList misc = new NameValuePairList();
    //misc["externalWindowHandle"] = handle.ToString();
    //mWindow = mRoot.CreateRenderWindow("Main RenderWindow", 800, 600, false, misc);
    }

    void InitResources()
    {
    TextureManager.Singleton.DefaultNumMipmaps = 5;
    ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
    }

    void CreateScene()
    {
    SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
    Camera cam = mgr.CreateCamera("Camera");
    mRoot.AutoCreatedWindow.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);

    mRoot.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded);
    ticks = Environment.TickCount;
    }

    void StartRenderLoop()
    {
    mRoot.StartRendering();

    //// Alternate Rendering Loop
    //while (mRoot.RenderOneFrame())
    //{
    // // Do other things here, such as sleep for a short period of time
    //}
    }

    bool FrameEnded(FrameEvent evt)
    {
    if (Environment.TickCount - ticks > 5000)
    return false;

    return true;
    }
    }
    }