[solved]create entity bug

andyhebear1

15-03-2012 02:42:50

err:Attempted to read or write protected memory. This is often an indication that other memory corrupted
in Mogre.SceneManager.CreateEntity(String entityName, String meshName)

the src:
if (part.Render.RenderScene.HasSceneNode(part.ID + "_Node")) {
part.Render.RenderScene.DestroySceneNode(part.ID + "_Node");
}
part.Render.RenderNode = part.Render.RenderScene.CreateSceneNode(part.ID + "_Node");
part.Render.RenderScene.RootSceneNode.AddChild(part.Render.RenderNode);
Entity _rob = null;

if (part.Render.RenderScene.HasEntity((part.ID + "_Entity" + i.ToString()))) {
part.Render.RenderScene.DestroyEntity((part.ID + "_Entity" + i.ToString()));
}
try {
_rob = part.Render.RenderScene.CreateEntity(part.ID + "_Entity" + i.ToString(), strName);//???
}
catch (Exception ex) {
try {
DebugLog.Log("创建实体出错 " + strName, ex, true);
Mogre.MeshManager.Singleton.Unload(strName);
Mogre.MeshManager.Singleton.Remove(strName);
Mogre.MeshManager.Singleton.Load(strName, "IRobotQ");
DebugLog.Log("重新加载模型 " + strName);
_rob = part.Render.RenderScene.CreateEntity(part.ID + "_Entity" + i.ToString(), strName);//???
}
catch (Exception ee) {
DebugLog.Log("无法创建实体 " + strName, ex, true);
throw new Exception("无法创建实体", ee);
}
}



the mesh is has
when i create the entity many time will throw this error

now this problem is solved: do destory scenenode and entity before,must DetachObject entity from this entity parentscenenode
and there cann't has same name mesh in 2 different resource group

if (entity.ParentSceneNode != null && (IntPtr)entity.ParentSceneNode.NativePtr != IntPtr.Zero) {
entity.ParentSceneNode.DetachObject(entity);
}

andyhebear1

15-03-2012 05:07:55

i use mogre 1.6.5

zarfius

15-03-2012 10:43:42

when i create the entity many time will throw this error
Are you saying you are creating lots of entities? If so, how many? You may be hitting some kind of limit.

Regardless, you might be able to get more of an idea about your error if you check the Ogre.log file.

You can also wrap your code in a try catch block that handles ogre exceptions like this:

try
{
// your code goes here
}
catch (SEHException ex) // SEHExceptions don't get caught like normal exceptions. You need to include this special exception handler
{
if (OgreException.IsThrown)
throw new Exception(OgreException.LastException.FullDescription, ex);
}

andyhebear1

16-03-2012 08:09:20

resources.cfg
# Resource locations to be added to the 'boostrap' path
# This also contains the minimum you need to use the Ogre example framework
[Bootstrap]
Zip=Media/packs/OgreCore.zip

# Resource locations to be added to the default path

[General]
FileSystem=Media
FileSystem=Media/Caelum
FileSystem=Media/fonts
FileSystem=Media/materials/programs
FileSystem=Media/materials/scripts
FileSystem=Media/materials/textures
FileSystem=Media/models
FileSystem=Media/overlays
FileSystem=Media/particle
FileSystem=Media/gui
FileSystem=Media/DeferredShadingMedia
FileSystem=Media/MyGUI_Media
Zip=Media/packs/cubemap.zip
Zip=Media/packs/cubemapsJS.zip
Zip=Media/packs/dragon.zip
Zip=Media/packs/fresneldemo.zip
Zip=Media/packs/ogretestmap.zip
Zip=Media/packs/skybox.zip
[IRobotQ]
FileSystem=Media/Avi
FileSystem=Media/ico
FileSystem=Media/sound
FileSystem=Media/IRQModel
FileSystem=Media/IRQModel/Material

i load a scene about has 400 count entity,
my code like this:
for(int i=0;i<400;i++)
{
//ToDo: create entity and scenenode
}
run about 1~5 minute and the end to close scene.
eg:
for(int i=0;i<400;i++)
{
//ToDo:destory entity and scenenode
}
Mogre.MeshManager.Singleton.UnloadUnreferencedResources();
Mogre.MaterialManager.Singleton.UnloadUnreferencedResources();
Mogre.TextureManager.Singleton.UnloadUnreferencedResources();
if (ResourceGroupManager.Singleton.IsResourceGroupLoaded("IRobotQ") == true) {
ResourceGroupManager.Singleton.UnloadResourceGroup("IRobotQ");
}
ResourceGroupManager.Singleton.UnloadUnreferencedResourcesInGroup("IRobotQ", false);
ResourceGroupManager.Singleton.UnloadUnreferencedResourcesInGroup("General", false);


load ->run->close to do this step many times.

some time to do this step count<10 will error.
some time to do this step count >1000 will not error.

andyhebear1

16-03-2012 08:16:41

dump 1:
FAULTING_THREAD: 00001488

PRIMARY_PROBLEM_CLASS: INVALID_POINTER_READ

BUGCHECK_STR: APPLICATION_FAULT_INVALID_POINTER_READ_INVALID_POINTER_WRITE

IP_ON_HEAP: 25030a78
The fault address in not in any loaded module, please check your build's rebase
log at <releasedir>\bin\build_logs\timebuild\ntrebase.log for module which may
contain the address if it were loaded.

IP_IN_VM_BLOCK: 25030a78

FRAME_ONE_INVALID: 1

LAST_CONTROL_TRANSFER: from 25030a78 to 77d37094

STACK_TEXT:
WARNING: Stack unwind information not available. Following frames may be wrong.
002fd0f8 25030a78 25030000 25030150 25030000 ntdll+0x47094
002fd0fc 25030000 25030150 25030000 0000005a 0x25030a78
002fd100 25030150 25030000 0000005a 25030150 0x25030000
002fd104 25030000 0000005a 25030150 70000171 0x25030150
002fd108 00000000 25030150 70000171 77d46524 0x25030000


FAULTING_SOURCE_CODE:
No source found for 'c:\devel\gamedevel\mogre 1.6\mogre\ogre\ogremain\src\nedmalloc\malloc.c.h'


SYMBOL_NAME: OgreMain!mspace_malloc+fc

FOLLOWUP_NAME: MachineOwner

MODULE_NAME: OgreMain

IMAGE_NAME: OgreMain.dll

DEBUG_FLR_IMAGE_TIMESTAMP: 4b41dfd3

STACK_COMMAND: .ecxr ; kb

FAILURE_BUCKET_ID: INVALID_POINTER_READ_c0000005_OgreMain.dll!mspace_malloc

BUCKET_ID: APPLICATION_FAULT_INVALID_POINTER_READ_INVALID_POINTER_WRITE_OgreMain!mspace_malloc+fc

WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/IRobotQ_exe/1_3_0_0/4f6065c3/OgreMain_dll/0_0_0_0/4b41dfd3/c0000005/000d84ac.htm?Retriage=1

Followup: MachineOwner

zarfius

16-03-2012 12:23:43

I'm not sure but your code looks very odd to me. I don't think you need to be cleaning up any resources like this, Ogre will do that for you. So unless you have a good reason don't do it.

There could be lots of things causing your problems. Maybe your deleting a resouce that's being used by an entity that hasn't been deleted or maybe it's caused from some other plugin (I noticed Caelum in your resources). Maybe it's a bug in another part of your code completely.

I'd probably head on over to the main Ogre forums and see if they can help.

andyhebear1

17-03-2012 01:59:59

Caelum has not used! and my mesh,texture and material resource are all in the [IRobotQ]Group
if i am not to do unload the ogre resource(in IRobotQ group ),the memory will add more when i load a other scene,
Special the Large number of scenes

zarfius

17-03-2012 09:38:16

I think I understand what you are trying to do but I'm afraid I've never done it before. Sorry I can't help you. If you don't get a reply here try the main Ogre forums, I suspect the problem is not a Mogre specific issue.

Beauty

11-04-2012 13:18:34

Perhaps the problem is the position of the curly bracket?

Look to my comments:
if (ResourceGroupManager.Singleton.IsResourceGroupLoaded("IRobotQ") == true) {
ResourceGroupManager.Singleton.UnloadResourceGroup("IRobotQ");
} // MAYBE MOVE THIS
ResourceGroupManager.Singleton.UnloadUnreferencedResourcesInGroup("IRobotQ", false);
ResourceGroupManager.Singleton.UnloadUnreferencedResourcesInGroup("General", false);
// TO HERE