Miyagi GUI/Viewport Dispose issues

XipherX

15-10-2012 16:24:22

Hi,

I'm currently using Mogre 1.7.1 with last repository Miyagi version Visual Studio 2012 and .NET framework 4.0.

The application uses a Mogre RenderWindow composed by multiple Mogre viewports and two Miyagi gui for each viewport.
Generally the application creates dinamically viewports as it needs them, the problem comes out when I have to dispose a single viewport.

Steps used for removing a single viewport (pseudo code):


// removing a mogre camera
_sceneManager.DestroyCamera(_mogreCamera);
_mogreCamera = null;

if (_cameraNode != null)
{
_sceneManager.DestroySceneNode(_cameraNode);
_cameraNode = null;
}

// removing a mogre viewport
if(_mogreViewport != null)
{
_graphicScene.CurrentEwpControl.RenderWindow.RemoveViewport(_zOrder);
_mogreViewport = null;
}

// removing the guis
var bIsGuiDisposed = true;

// first gui
if (_guiViewport != null)
{
_guiViewport.SpriteRenderer.Viewport = null;
_guiViewport.Dispose();
bIsGuiDisposed = _guiViewport.IsDisposed;
_guiViewport = null;
}

// second gui
if (_guiObjectMenu != null)
{
_guiObjectMenu.SpriteRenderer.Viewport = null;
_guiObjectMenu.Dispose();
bIsGuiDisposed = bIsGuiDisposed && _guiObjectMenu.IsDisposed;
_guiObjectMenu = null;
}

_bIsDisposed = bIsGuiDisposed;


After that I update the current active viewport of Miyagi system as follows:


_currentViewport = activeViewport;
_mainCamera = _currentViewport.Camera;
// manage of Miyagi render manager
var miyagiMogreRenderManager = (Miyagi.Backend.Mogre.MogreRenderManager) GUISystem.RenderManager;
miyagiMogreRenderManager.SceneManager = null;
miyagiMogreRenderManager.SceneManager = _sceneManager;
// active viewport (working)
var miyagiViewport = _currentViewport.GUIViewport.SpriteRenderer.Viewport;
GUISystem.RenderManager.MainViewport = null;
GUISystem.RenderManager.MainViewport = miyagiViewport;
GUISystem.Backend.RenderManager.MainViewport = miyagiViewport;


But at this point when rendering process run I catch the following exception:

AccesViolationException......
in Mogre.HardwareIndexBufferSharedPtr.!HardwareIndexBufferSharedPtr()
in Mogre.HardwareIndexBufferSharedPtr.Dispose(Boolean )
in Mogre.HardwareIndexBufferSharedPtr.Finalize()

Please, can I have an help? Thx in advanced

smiley80

17-10-2012 10:26:06

I can't reproduce this. But it looks like something isn't disposed correctly. Make sure you also call Dispose on the Mogre stuff, esp. *Ptr classes.

XipherX

25-10-2012 13:58:12

I can't reproduce this. But it looks like something isn't disposed correctly. Make sure you also call Dispose on the Mogre stuff, esp. *Ptr classes.

Hi Smiley,
to reproduce a similar error you can use your "Miyagi-1.2.0-examples" selecting OpenGL and Mogre.
Select GUI example and press start button. Then click on Exit button and we get the following error:

in Ogre.IndexData.{dtor}(IndexData* )
in Mogre.IndexData.Dispose(Boolean )
in Mogre.IndexData.Dispose()
in Miyagi.Backend.Mogre.MogreSpriteRenderer2D.DestroyHardwareBuffer() in E:\ProgettoEWP\Miyagi\Projects\Backends\Miyagi.Backend.Mogre\MogreSpriteRenderer2D.cs:riga 474
in Miyagi.Backend.Mogre.MogreSpriteRenderer2D.Dispose(Boolean disposing) in E:\ProgettoEWP\Miyagi\Projects\Backends\Miyagi.Backend.Mogre\MogreSpriteRenderer2D.cs:riga 196
in Miyagi.Common.Rendering.SpriteRenderer.Dispose() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\Common\Rendering\SpriteRenderer.cs:riga 229
in Miyagi.Common.Rendering.RenderManager.DestroyRenderer(ISpriteRenderer renderer) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\Common\Rendering\RenderManager.cs:riga 269
in Miyagi.UI.GUI.DestroySpriteRenderer() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUI.cs:riga 489
in Miyagi.UI.GUIManager.RemoveGUI(GUI g) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUIManager.cs:riga 1195
in Miyagi.UI.GUIManager.OnGUIRemoved(Object sender, CollectionEventArgs`1 e) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUIManager.cs:riga 1188
in Miyagi.Common.MiyagiCollection`1.Remove(T item) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\Common\MiyagiCollection.cs:riga 444
in Miyagi.UI.GUI.Dispose(Boolean disposing) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUI.cs:riga 578
in Miyagi.UI.GUI.Dispose() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUI.cs:riga 283
in Miyagi.UI.GUIManager.DisposeAllGUIs() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUIManager.cs:riga 449
in Miyagi.UI.GUIManager.Dispose(Boolean disposing) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUIManager.cs:riga 855
in Miyagi.UI.GUIManager.Dispose() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\UI\GUIManager.cs:riga 435
in Miyagi.Common.MiyagiSystem.UnregisterManager(IManager manager) in E:\ProgettoEWP\Miyagi\Projects\Miyagi\Common\MiyagiSystem.cs:riga 551
in Miyagi.Common.MiyagiSystem.Dispose() in E:\ProgettoEWP\Miyagi\Projects\Miyagi\Common\MiyagiSystem.cs:riga 398
in MogreLauncher.MogreDemo.Stop() in E:\ProgettoEWP\Miyagi\Projects\Examples\Mogre\MogreDemo.cs:riga 60
in Examples.Helper.Example.Stop() in E:\ProgettoEWP\Miyagi\Projects\Examples\Common\Helper\Example.cs:riga 56
in Examples.Helper.ExampleSelector.ExampleProxy.Stop() in E:\ProgettoEWP\Miyagi\Projects\Examples\Common\Helper\ExampleSelector.cs:riga 314
in Examples.Helper.ExampleSelector.ExampleProxy.Stop()
in Examples.Helper.ExampleSelector.StopExample() in E:\ProgettoEWP\Miyagi\Projects\Examples\Common\Helper\ExampleSelector.cs:riga 188
in Examples.Helper.ExampleSelector.Button2Click(Object sender, EventArgs e) in E:\ProgettoEWP\Miyagi\Projects\Examples\Common\Helper\ExampleSelector.cs:riga 48
in System.Windows.Forms.Control.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ButtonBase.WndProc(Message& m)
in System.Windows.Forms.Button.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
in System.Windows.Forms.Application.Run(Form mainForm)
in Examples.Program.Main() in E:\ProgettoEWP\Miyagi\Projects\Examples\Common\Program.cs:riga 19
in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()


I have modified the "Examples.exe.config" file for working with .NET framework 4.0.

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration


Selecting DirectX doesn't crash but I have to use Opengl in my project.
Any idea?

MAny Thanks!

smiley80

25-10-2012 14:27:38

Should be fixed in the latest revision.

XipherX

12-11-2012 13:33:43

Hi Smiley,

sorry for the delay....., I'm currently using the latest downloadable version (hg) of Miyagi but the problem still remain.
The Hg workbench tell me that the is no other version available.

Any idea?

smiley80

12-11-2012 18:34:03

You're probably using the SourceForge repo, please change it to Bitbucket:
https://bitbucket.org/tbohnen/miyagi/src