feanor91
29-08-2008 08:20:03
Hello
It's the stupid man another time....
This time I want to know how to cleanup all that mess when quiting...I explain
My soft is not all in 3D. I call my 3D window to show something, then closing it, then reopen it and so on. All work fine, exept if I put reflections on. The first time I open it, that's OK, but when I close and reopen it, the sub reflection crash on call to createplane. here's my code :
My dispose sub :
Reflection sub crash here :
or here :
It says that It can write on protected memory. If think that is because some pointer are not free, but, ogre shutdown properly when I close window. here the end of my ogre.log :
So what?
It's the stupid man another time....
This time I want to know how to cleanup all that mess when quiting...I explain
My soft is not all in 3D. I call my 3D window to show something, then closing it, then reopen it and so on. All work fine, exept if I put reflections on. The first time I open it, that's OK, but when I close and reopen it, the sub reflection crash on call to createplane. here's my code :
Public Sub ReflectionOn()
'Permet d'initialiser les reflections ou de les réactiver si elles avaient été suspendue
'Allow to initialise reflection or reactivat it if the have been suspended
If ReflectInit Then 'si elle ont été suspendus, alors, on les réactive / if suspended, reactivate it
mPlaneEnt.Visible = True 'on montre le plan de réflection / showing reflection plane
_mReflectSceneNode.GetAttachedObject(CType(0, UShort)).Visible = False 'on cache l'objet de base / hiding base object
ReflectOn = True 'on réfléchit / recflection on
Exit Sub
End If
ReflectionPlane.normal = _ReflectPlaneNormal 'par défaut un plan horizontal / horizontal plane
ReflectionPlane.d = 0 '?
'Creation du plan / plane creation
Mogre.MeshManager.Singleton.CreatePlane("ReflectPlane", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, ReflectionPlane, 1024, 1024, 16, 16, True, 1, 1, 1, Mogre.Vector3.UNIT_Z)
'Tou ce qui suit est pour ajouter le plan à la scene / all that follow is to add plane to scene
mPlaneEnt = _OgreSceneManager.CreateEntity("ReflectPlaneEnt", "ReflectPlane")
mPlaneNode = _OgreSceneManager.RootSceneNode.CreateChildSceneNode
mPlaneNode.AttachObject(mPlaneEnt)
'Le plan pend les même taile et position que l'objet de base / plane take same size and position than base object
mPlaneNode.Position = _mReflectSceneNode.Position
mPlaneNode.Orientation = _mReflectSceneNode.Orientation
mPlaneNode.Scale(_mReflectSceneNode.GetScale)
'Creation de la texture pour le calcul des réflections / texture creation for reflection
Dim texture As Mogre.TexturePtr = Mogre.TextureManager.Singleton.CreateManual("RttTex", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, CType(512, UInteger), CType(512, UInteger), 0, Mogre.PixelFormat.PF_R8G8B8, Mogre.TextureUsage.TU_RENDERTARGET)
rttTex = texture.GetBuffer.GetRenderTarget()
'Creation du viewport pour calculer les réflections / creation of reflection viewport
Dim v As Mogre.Viewport = rttTex.AddViewport(_OgreCamera)
v.SetClearEveryFrame(True)
v.BackgroundColour = Mogre.ColourValue.Black
'Récupération de la texture de l'objet de base / getting texture from base object
Dim OrigObjet As Mogre.Entity = _mReflectSceneNode.GetAttachedObject(CType(0, UShort))
Dim MatToBlend As Mogre.MaterialPtr = OrigObjet.GetSubEntity(CType(0, UShort)).GetMaterial().Clone("ReflectMat") 'on la clone pour ne pas alterer celle de l'objet / cloning it to not alter base object texture
'on crè une nouvelle technique dans la texture / creation of a new ehcnique in texture
Dim t As Mogre.TextureUnitState = MatToBlend.GetTechnique(CType(0, UShort)).GetPass(CType(0, UShort)).CreateTextureUnitState("RttTex")
'on récupère la première technique de la texture pour permettre sa mise à l'échelle / getting first technique to scaling texture
Dim t1 As Mogre.TextureUnitState = MatToBlend.GetTechnique(CType(0, UShort)).GetPass(CType(0, UShort)).GetTextureUnitState(CType(0, UShort))
'le paramètrage pour le fondu des deux texture / applying param to blend textures
t.SetColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL, LayerBlendSource.LBS_TEXTURE, LayerBlendSource.LBS_CURRENT, Mogre.ColourValue.White, Mogre.ColourValue.White, _ReflecionIntensity)
t.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP)
t.SetProjectiveTexturing(True, _OgreCamera)
MatToBlend.SetSceneBlending(_SceneBlendingType)
'mise à l'échelle de la première texture / scaling first texture
t1.TextureUScale = _UScaleReflect
t1.TextureVScale = _vScaleReflect
'on affecte les évènement à faire avant et après rendu du viewport / affecting event in pre and post viewport render
AddHandler rttTex.PostRenderTargetUpdate, AddressOf postRenderTargetUpdate
AddHandler rttTex.PreRenderTargetUpdate, AddressOf preRenderTargetUpdate
'on affecte le materiel au plan / adding material to plan
mPlaneEnt.SetMaterialName(MatToBlend.Name)
OrigObjet.Visible = False 'on cache l'objet de base / hiding base object
ReflectOn = True 'on active les réflections / activate reflection
ReflectInit = True 'les reflection on été initialisées / reflection are initialised
End Sub
My dispose sub :
Public Sub DisposeOgre()
'Pemet de nettoyer les instances OGRES en cas de rechargement de la scène ou de l'ouverture d'une nouvelle
'Allow to destroy all ogre instances
Mogre.MeshManager.Singleton.Remove("ReflectPlane")
Mogre.MeshManager.Singleton.Dispose()
ResourceGroupManager.Singleton.DestroyResourceGroup("General")
ResourceGroupManager.Singleton.Dispose()
_RenderWindow.RemoveAllViewports()
_OgreRacine.DetachRenderTarget(_RenderWindow)
_RenderWindow.Destroy()
_OgreRacine.DestroySceneManager(_OgreSceneManager)
_OgreRacine.DestroyAllRenderQueueInvocationSequences()
_OgreRacine.Shutdown()
_OgreRacine.Dispose()
End Sub
Reflection sub crash here :
Mogre.MeshManager.Singleton.CreatePlane("ReflectPlane", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, ReflectionPlane, 1024, 1024, 16, 16, True, 1, 1, 1, Mogre.Vector3.UNIT_Z)
or here :
Dim texture As Mogre.TexturePtr = Mogre.TextureManager.Singleton.CreateManual("RttTex", Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, CType(512, UInteger), CType(512, UInteger), 0, Mogre.PixelFormat.PF_R8G8B8, Mogre.TextureUsage.TU_RENDERTARGET)
It says that It can write on protected memory. If think that is because some pointer are not free, but, ogre shutdown properly when I close window. here the end of my ogre.log :
09:17:10: ********************************
09:17:10: ** oSceneLoader: Scene loaded **
09:17:10: ********************************
09:17:10: Creating viewport on target 'rtt/61073984', rendering from camera 'Camera01', relative dimensions L: 0.00 T: 0.00 W: 1.00 H: 1.00 ZOrder: 0
09:17:10: WARNING: Texture instance 'RttTex' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
09:17:11: Texture: spot_shadow_fade.png: Loading 1 faces(PF_R8G8B8,128x128x1) with 7 generated mipmaps from Image. Internal format is PF_X8R8G8B8,128x128x1.
09:17:15: Destroying resource group General
09:17:15: Unloading resource group General
09:17:15: Finished unloading resource group General
09:17:15: Render Target 'rtt/61073984' Average FPS: 81.1977 Best FPS: 114.77 Worst FPS: 71.8504
09:17:15: *-*-* OGRE Shutdown
09:17:15: *-*-* OGRE Shutdown
09:17:15: Unregistering ResourceManager for type Compositor
09:17:15: Unregistering ResourceManager for type Font
09:17:15: Unregistering ResourceManager for type Skeleton
09:17:15: Unregistering ResourceManager for type Mesh
09:17:15: Unregistering ResourceManager for type HighLevelGpuProgram
09:17:15: Uninstalling plugin: GL RenderSystem
09:17:15: *** Stopping Win32GL Subsystem ***
09:17:15: Plugin successfully uninstalled
09:17:15: Unloading library .\Plugins\RenderSystem_GL
09:17:15: Uninstalling plugin: D3D9 RenderSystem
09:17:15: D3D9 : Shutting down cleanly.
09:17:15: Unregistering ResourceManager for type Texture
09:17:15: Unregistering ResourceManager for type GpuProgram
09:17:15: D3D9 : Direct3D9 Rendering Subsystem destroyed.
09:17:15: Plugin successfully uninstalled
09:17:15: Unloading library .\Plugins\RenderSystem_Direct3D9
09:17:15: Unregistering ResourceManager for type Material
So what?