locked
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RRS feed

  • Question

  • Hello,

    I have had issues with adding and deleting visual entitys in the Robotics simulation, it starts off with "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." and sometimes other c++ error messages. Eventually it winds up with visual enititys in the simulation that im unable to delete. I have been able to get around it by creating multiple application domains and when the robotics engine fails create another application domain and start the robotics engine again. This is of course not an ideal soultion, marshling objects across domains is not the way to go.


    Observations so far - The faster the computer and the more cpu's the more i see it so i suspect a threading issue.

    I have been able to recreate my issue in the SimulationEntityProject here is the code below.

    Also if i use a iRobotCreate instead i see the error below

    PhysicsErrorStream: Assert reported.    Message:0
        File:g:\scm\release\PhysX_2.8.1\novodex\SDKs\Core\Common\src\ArticulationNod
    e.cpp
        Line:216
    PhysicsErrorStream: Assert reported.    Message:0
        File:g:\scm\release\PhysX_2.8.1\novodex\SDKs\Core\Common\src\ArticulationNod
    e.cpp
        Line:216

    Any thoughts or idea's would be greatly appreciated.

    Andrew Fraser.

    //-----------------------------------------------------------------------
    
    
    
    //  This file is part of Microsoft Robotics Developer Studio Code Samples.
    
    
    
    //
    
    
    
    //  Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    
    //
    
    
    
    //  $File: SimulationEmptyProject.cs $ $Revision: 3 $
    
    
    
    //-----------------------------------------------------------------------
    
    
    
    using System;
    
    
    
    using System.Collections.Generic;
    
    
    
    using System.ComponentModel;
    
    
    
    using System.Diagnostics;
    
    
    
    using System.Threading;
    
    
    
    using Microsoft.Ccr.Core;
    
    
    
    using Microsoft.Dss.Core.Attributes;
    
    
    
    using Microsoft.Dss.ServiceModel.Dssp;
    
    
    
    using Microsoft.Dss.ServiceModel.DsspServiceBase;
    
    
    
    using Microsoft.Robotics.PhysicalModel;
    
    
    
    using Microsoft.Robotics.Simulation.Engine;
    
    
    
    using Microsoft.Robotics.Simulation.Physics;
    
    
    
    using W3C.Soap;
    
    
    
    using submgr = Microsoft.Dss.Services.SubscriptionManager;
    
    
    
    using engine = Microsoft.Robotics.Simulation.Engine.Proxy;
    
    
    
    
    
    
    
    namespace Robotics.SimulationEmptyProject
    
    
    
    {
    
    
    
        [Contract(Contract.Identifier)]
    
    
    
        [DisplayName("(User) Simulation Empty Project")]
    
    
    
        [Description("Minimal base template for developing a service that uses the simulation engine")]
    
    
    
        class SimulationEmptyProjectService : DsspServiceBase
    
    
    
        {
    
    
    
            /// <summary>
    
    
    
            /// Service state
    
    
    
            /// </summary>
    
    
    
            [ServiceState]
    
    
    
            SimulationEmptyProjectState _state = new SimulationEmptyProjectState();
    
    
    
    
    
    
    
            /// <summary>
    
    
    
            /// Main service port
    
    
    
            /// </summary>
    
    
    
            [ServicePort("/SimulationEmptyProject", AllowMultipleInstances = true)]
    
    
    
            SimulationEmptyProjectOperations _mainPort = new SimulationEmptyProjectOperations();
    
    
    
    
    
    
    
            [SubscriptionManagerPartner]
    
    
    
            submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();
    
    
    
    
    
    
    
            /// <summary>
    
    
    
            /// SimulationEngine partner
    
    
    
            /// </summary>
    
    
    
            [Partner("SimulationEngine", Contract = engine.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
    
    
    
            engine.SimulationEnginePort _simulationEnginePort = new engine.SimulationEnginePort();
    
    
    
            engine.SimulationEnginePort _simulationEngineNotify = new engine.SimulationEnginePort();
    
    
    
    
    
    
    
            private Timer updateTimer;
    
    
    
            private readonly List<VisualEntity> _entitys = new List<VisualEntity>(10);
    
    
    
            private readonly Random _rnd = new Random();
    
    
    
            private readonly TimeSpan _changeWait = new TimeSpan(0, 0, 0, 2);
    
    
    
    
    
    
    
            /// <summary>
    
    
    
            /// Service constructor
    
    
    
            /// </summary>
    
    
    
            public SimulationEmptyProjectService(DsspServiceCreationPort creationPort)
    
    
    
                : base(creationPort)
    
    
    
            {
    
    
    
            }
    
    
    
    
    
    
    
            /// <summary>
    
    
    
            /// Service start
    
    
    
            /// </summary>
    
    
    
            protected override void Start()
    
    
    
            {
    
    
    
    
    
    
    
                // 
    
    
    
                // Add service specific initialization here
    
    
    
                // 
    
    
    
    
    
    
    
                base.Start();
    
    
    
    
    
    
    
                AddGround();
    
    
    
                AddSky();
    
    
    
    
    
    
    
                SetupCamera();
    
    
    
    
    
    
    
                updateTimer = new Timer(UpdateScene, null, new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 0, 0, 10));
    
    
    
    
    
    
    
            }
    
    
    
    
    
    
    
            private void UpdateScene(object state)
    
    
    
            {
    
    
    
                lock (this)
    
    
    
                {
    
    
    
                    // if not full add one
    
    
    
                    if (_entitys.Count < _entitys.Capacity)
    
    
    
                    {
    
    
    
                        var newEntity = CreateBox(); 
    
    
    
                        if (newEntity != null)
    
    
    
                            _entitys.Add(newEntity);
    
    
    
                    }
    
    
    
                    else
    
    
    
                    {
    
    
    
                        DeleteRandomEntity();
    
    
    
                    }
    
    
    
                }
    
    
    
            }
    
    
    
    
    
    
    
            private VisualEntity DeleteRandomEntity()
    
    
    
            {
    
    
    
                int deleteIndex = _rnd.Next(_entitys.Count);
    
    
    
    
    
    
    
                var deletedVisualEntity = _entitys[deleteIndex];
    
    
    
                var deleteResetEvent = new ManualResetEvent(false);
    
    
    
    
    
    
    
                SpawnIterator(deletedVisualEntity, deleteResetEvent, SpawnedDeleteEntity);
    
    
    
    
    
    
    
                if (!deleteResetEvent.WaitOne(_changeWait))
    
    
    
                {
    
    
    
                    const string errorMsg = "Error waiting on DELETE sync";
    
    
    
                    Trace.WriteLine(errorMsg);
    
    
    
                }
    
    
    
    
    
    
    
                _entitys.Remove(deletedVisualEntity);
    
    
    
    
    
    
    
                return deletedVisualEntity;
    
    
    
            }
    
    
    
    
    
    
    
            static IEnumerator<ITask> SpawnedDeleteEntity(VisualEntity entity, ManualResetEvent manualResetEvent)
    
    
    
            {
    
    
    
                if (entity == null)
    
    
    
                    yield break;
    
    
    
    
    
    
    
                SimulationEngine.GlobalInstancePort.Delete(entity);
    
    
    
    
    
    
    
                var faultOrFound = SimulationEngine.GlobalInstancePort.Query(entity);
    
    
    
                yield return faultOrFound.Choice();
    
    
    
    
    
    
    
                // if its a fault exit
    
    
    
                var fault = (Fault)faultOrFound;
    
    
    
                if (fault != null)
    
    
    
                {
    
    
    
                    if ((fault.Node == null) && (fault.Code == null) && (fault.Detail == null) && (fault.Reason == null) && (fault.Role == null))
    
    
    
                    {
    
    
    
                        //Trace.WriteLine("Entity deleted");
    
    
    
                        // signal as being done
    
    
    
                        manualResetEvent.Set();
    
    
    
                    }
    
    
    
                    else
    
    
    
                    {
    
    
    
                        Trace.WriteLine(fault.ToException());
    
    
    
                        manualResetEvent.Set();
    
    
    
                    }
    
    
    
                    yield break;
    
    
    
                }
    
    
    
    
    
    
    
                var found = (QuerySimulationEntityResponseType)faultOrFound;
    
    
    
                if (found != null)
    
    
    
                {
    
    
    
                    string restartMsg = "Error deleting : " + found.Entity.State.Name;
    
    
    
                    Trace.WriteLine(restartMsg);
    
    
    
    
    
    
    
                    // restart on error
    
    
    
                    manualResetEvent.Set();
    
    
    
                    yield break;
    
    
    
                }
    
    
    
    
    
    
    
    
    
    
    
                yield break;
    
    
    
            }
    
    
    
    
    
    
    
            public VisualEntity CreateBox()
    
    
    
            {
    
    
    
                Vector3 dimensions = new Vector3(0.2f, 0.2f, 0.2f); // meters
    
    
    
    
    
    
    
                // create simple movable entity, with a single shape
    
    
    
                var box = new SingleShapeEntity(
    
    
    
                    new BoxShape(
    
    
    
                        new BoxShapeProperties(
    
    
    
                            1, // mass in kilograms.
    
    
    
                            new Pose(), // relative pose
    
    
    
                            dimensions)), // dimensions
    
    
    
                    new Vector3(1, 1, 1)) { SuspendUpdates = true };
    
    
    
    
    
    
    
                box.State.MassDensity.Mass = 0;
    
    
    
                box.State.MassDensity.Density = 0;
    
    
    
    
    
    
    
                // Name the entity. All entities must have unique names
    
    
    
                box.State.Name = "box : " + Guid.NewGuid();
    
    
    
    
    
    
    
                return InsertVisualEntity(box);
    
    
    
            }
    
    
    
    
    
    
    
            private VisualEntity InsertVisualEntity(VisualEntity visualEntity)
    
    
    
            {
    
    
    
                var InsertEvent = new ManualResetEvent(false);
    
    
    
                SimulationEngine.GlobalInstancePort.Insert(visualEntity);
    
    
    
    
    
    
    
                // check for any faults
    
    
    
                Activate(
    
    
    
                    Arbiter.Choice(SimulationEngine.GlobalInstancePort.Query(visualEntity),
    
    
    
                                   delegate
    
    
    
                                   {
    
    
    
                                       Trace.WriteLine("Added " + visualEntity);
    
    
    
                                       InsertEvent.Set();
    
    
    
                                   },
    
    
    
                                   delegate(Fault f)
    
    
    
                                   {
    
    
    
                                       string errorMsg = string.Format("Error Init {0} : {1}", visualEntity.GetType(), visualEntity);
    
    
    
    
    
    
    
                                       if ((f.Node == null) && (f.Code == null) && (f.Detail == null) && (f.Reason == null) && (f.Role == null))
    
    
    
                                       {
    
    
    
                                           Trace.WriteLine(errorMsg);
    
    
    
                                       }
    
    
    
                                       else
    
    
    
                                       {
    
    
    
                                           Trace.WriteLine(f.ToException());
    
    
    
                                       }
    
    
    
    
    
    
    
                                       InsertEvent.Set();
    
    
    
                                   }
    
    
    
                        ));
    
    
    
    
    
    
    
                Trace.WriteLine(string.Format("Waiting - Inserting Organism {0}", visualEntity));
    
    
    
                if (!InsertEvent.WaitOne(_changeWait))
    
    
    
                {
    
    
    
                    const string errorMsg = "Error waiting on INSERT sync";
    
    
    
                    Trace.WriteLine(errorMsg);
    
    
    
                }
    
    
    
    
    
    
    
                if (!visualEntity.HasBeenInitialized)
    
    
    
                {
    
    
    
                    Trace.WriteLine(string.Format("HasBeenInitialized failed on {0}", visualEntity));
    
    
    
                    return null;
    
    
    
                }
    
    
    
    
    
    
    
                visualEntity.SuspendUpdates = false;
    
    
    
    
    
    
    
                return visualEntity;
    
    
    
            }
    
    
    
    
    
    
    
            private void AddGround()
    
    
    
            {
    
    
    
                // create a large horizontal plane, at zero elevation.
    
    
    
                HeightFieldEntity ground = new HeightFieldEntity(
    
    
    
                    "simple ground", // name
    
    
    
                    "03RamieSc.dds", // texture image
    
    
    
                    new MaterialProperties("ground",
    
    
    
                        0.2f, // restitution
    
    
    
                        0.5f, // dynamic friction
    
    
    
                        0.5f) // static friction
    
    
    
                    );
    
    
    
                SimulationEngine.GlobalInstancePort.Insert(ground);
    
    
    
            }
    
    
    
    
    
    
    
            /// <summary>Add a sky</summary>
    
    
    
            private void AddSky()
    
    
    
            {
    
    
    
                // Add a sky using a static texture. We will use the sky texture
    
    
    
                // to do per pixel lighting on each simulation visual entity
    
    
    
                SkyDomeEntity sky = new SkyDomeEntity("skydome.dds", "sky_diff.dds");
    
    
    
                SimulationEngine.GlobalInstancePort.Insert(sky);
    
    
    
    
    
    
    
                // Add a directional light to simulate the sun.
    
    
    
                LightSourceEntity sun = new LightSourceEntity();
    
    
    
                sun.State.Name = "Sun";
    
    
    
                sun.Type = LightSourceEntityType.Directional;
    
    
    
                sun.Color = new Vector4(0.8f, 0.8f, 0.8f, 1);
    
    
    
                sun.Direction = new Vector3(0.5f, -.75f, 0.5f);
    
    
    
                SimulationEngine.GlobalInstancePort.Insert(sun);
    
    
    
            }
    
    
    
    
    
    
    
            private void SetupCamera()
    
    
    
            {
    
    
    
                // Set up initial view
    
    
    
                CameraView view = new CameraView();
    
    
    
                view.EyePosition = new Vector3(0f, 10f, 0f);
    
    
    
                view.LookAtPoint = new Vector3(0f, 0f, 0f);
    
    
    
                SimulationEngine.GlobalInstancePort.Update(view);
    
    
    
            }
    
    
    
        }
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Thursday, February 4, 2010 10:42 PM

Answers

  • The problem might be with the way that you are using some of the simulator operations. The confusion arises because there are methods defined on the GlobalInstancePort that look like normal methods but actually post messages to the port. If you don't do a yield return to wait for the response, then your code will keep on running and try to access things that might not exist yet.

    So the simple rule is: Any time you call a method on GlobalInstancePort, e.g. SimulationEngine.GlobalInstancePort.Delete(entity), you must wait for a response. Check the return type of the method (Intellisense will show you this) and you should see that it is a PortSet.

    Trevor

    Friday, February 19, 2010 6:38 PM

All replies

  • The problem might be with the way that you are using some of the simulator operations. The confusion arises because there are methods defined on the GlobalInstancePort that look like normal methods but actually post messages to the port. If you don't do a yield return to wait for the response, then your code will keep on running and try to access things that might not exist yet.

    So the simple rule is: Any time you call a method on GlobalInstancePort, e.g. SimulationEngine.GlobalInstancePort.Delete(entity), you must wait for a response. Check the return type of the method (Intellisense will show you this) and you should see that it is a PortSet.

    Trevor

    Friday, February 19, 2010 6:38 PM
  • Hello Trevor,

    Thanks for your reply, I have refactored the code to use "InsertSimulationEntity"  as per below which i can do a yield return with.
            IEnumerator<ITask> SpawnedInsertVisualEntity(engine.VisualEntity visualEntity, ManualResetEvent insertEvent)
            {
                if (visualEntity == null)
                    yield break;
    
                var insertSimulationEntity = _simulationEnginePort.InsertSimulationEntity(visualEntity);
                yield return insertSimulationEntity.Choice();
    
                var fault1 = (Fault)insertSimulationEntity;
                if (fault1 != null)
                {
                    Trace.WriteLine(fault1);
                }
    
                var insert = (DefaultInsertResponseType)insertSimulationEntity;
                Trace.WriteLine(insert);
                insertEvent.Set();
                yield break;
            }
    and the equivalent for deleteing the simulation entity however i still get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    I have copied the entire code to the below post, maybe you can spot what im doing wrong?

    Thanks, Andrew Fraser.

    //-----------------------------------------------------------------------
    //  This file is part of Microsoft Robotics Developer Studio Code Samples.
    //
    //  Copyright (C) Microsoft Corporation.  All rights reserved.
    //
    //  $File: SimulationEmptyProject.cs $ $Revision: 3 $
    //-----------------------------------------------------------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Threading;
    using Microsoft.Ccr.Core;
    using Microsoft.Dss.Core.Attributes;
    using Microsoft.Dss.ServiceModel.Dssp;
    using Microsoft.Dss.ServiceModel.DsspServiceBase;
    using Microsoft.Robotics.Simulation;
    using Microsoft.Robotics.Simulation.Engine;
    using Microsoft.Robotics.Simulation.Physics;
    using W3C.Soap;
    using BoxShape = Microsoft.Robotics.Simulation.Physics.Proxy.BoxShape;
    using BoxShapeProperties = Microsoft.Robotics.Simulation.Physics.Proxy.BoxShapeProperties;
    using engine = Microsoft.Robotics.Simulation.Engine.Proxy;
    using EntityState = Microsoft.Robotics.Simulation.Proxy.EntityState;
    using MassDensity = Microsoft.Robotics.Simulation.Physics.Proxy.MassDensity;
    using Pose = Microsoft.Robotics.PhysicalModel.Proxy.Pose;
    using RenderingAssets = Microsoft.Robotics.Simulation.Proxy.RenderingAssets;
    using Vector3 = Microsoft.Robotics.PhysicalModel.Proxy.Vector3;
    
    
    namespace Robotics.SimulationEmptyProject
    {
        [Contract(Contract.Identifier)]
        [DisplayName("(User) Simulation Empty Project")]
        [Description("Minimal base template for developing a service that uses the simulation engine")]
        class SimulationEmptyProjectService : DsspServiceBase
        {
            /// <summary>
            /// Service state
            /// </summary>
            [ServiceState]
            SimulationEmptyProjectState _state = new SimulationEmptyProjectState();
    
            /// <summary>
            /// Main service port
            /// </summary>
            [ServicePort("/SimulationEmptyProject", AllowMultipleInstances = true)]
            SimulationEmptyProjectOperations _mainPort = new SimulationEmptyProjectOperations();
    
            //[SubscriptionManagerPartner]
            //submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();
    
            /// <summary>
            /// SimulationEngine partner
            /// </summary>
            [Partner("SimulationEngine", Contract = engine.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
            readonly engine.SimulationEnginePort _simulationEnginePort = new engine.SimulationEnginePort();
            //engine.SimulationEnginePort _simulationEngineNotify = new engine.SimulationEnginePort();
    
            private Timer updateTimer;
            private readonly List<engine.VisualEntity> _entitys = new List<engine.VisualEntity>(10);
            private readonly Random _rnd = new Random();
            private readonly TimeSpan _changeWait = new TimeSpan(0, 0, 0, 2);
    
            /// <summary>
            /// Service constructor
            /// </summary>
            public SimulationEmptyProjectService(DsspServiceCreationPort creationPort)
                : base(creationPort)
            {
            }
    
            /// <summary>
            /// Service start
            /// </summary>
            protected override void Start()
            {
                base.Start();
    
                AddGround();
                AddSky();
                SetupCamera();
    
                updateTimer = new Timer(UpdateScene, null, new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 0, 0, 1));
            }
    
            private void UpdateScene(object state)
            {
                lock (this)
                {
                    Trace.WriteLine("UpdateingScene");
    
                    // if not full add one
                    if (_entitys.Count < _entitys.Capacity)
                    {
                        var newEntity = CreateBox();  //CreateiRobot(); //  //
                        if (newEntity != null)
                            _entitys.Add(newEntity);
                    }
                    else
                    {
                        DeleteRandomEntity();
                    }
    
                }
            }
    
            private void DeleteRandomEntity()
            {
                int deleteIndex = _rnd.Next(_entitys.Count);
    
                var deletedVisualEntity = _entitys[deleteIndex];
                var deleteResetEvent = new ManualResetEvent(false);
    
                SpawnIterator(deletedVisualEntity, deleteResetEvent, SpawnedDeleteEntity);
    
                deleteResetEvent.WaitOne();
                _entitys.Remove(deletedVisualEntity);
    
                return;
            }
    
            IEnumerator<ITask> SpawnedDeleteEntity(engine.VisualEntity entity, ManualResetEvent manualResetEvent)
            {
                if (entity == null)
                    yield break;
    
                var deleteSimulationEntity = _simulationEnginePort.DeleteSimulationEntity(entity);
    
                yield return deleteSimulationEntity.Choice();
    
                var fault = (Fault)deleteSimulationEntity;
                if (fault != null)
                {
                    Trace.WriteLine(fault);
                }
    
                var deleteReponse = (DefaultDeleteResponseType)deleteSimulationEntity;
                if (deleteReponse != null)
                {
                    Trace.WriteLine(deleteReponse);
                }
    
                manualResetEvent.Set();
                yield break;
            }
    
            public engine.VisualEntity CreateBox()
            {
                var dimensions = new Microsoft.Robotics.PhysicalModel.Proxy.Vector3(0.2f, 0.2f, 0.2f); // meters
                // create simple movable entity, with a single shape
                //entityTest.
                var box = new engine.SingleShapeEntity();
    
    
                box.BoxShape = new BoxShape();
                box.BoxShape.BoxState = new BoxShapeProperties();
                //box.BoxShape.BoxState.
                //            1, // mass in kilograms.
                //            new Pose(), // relative pose
                //            dimensions)), // dimensions
                //    new Vector3(1, 1, 1)) { SuspendUpdates = true };
    
                // box.BoxShape.BoxState.LocalPose = new Pose { Position = new Vector3(1 , 1, 1) };
                box.BoxShape.BoxState.Dimensions = dimensions;
                box.BoxShape.BoxState.MassDensity = new MassDensity { Mass = 1, Density = 1 };
                //box.BoxShape.BoxState.Name = "box : " + Guid.NewGuid();
                box.State = new EntityState();
    
                // Name the entity. All entities must have unique names
                box.State.Name = "box : " + Guid.NewGuid();
                box.State.Pose = new Pose() { Position = new Vector3(0, 1, 0) };
                box.State.MassDensity = new MassDensity() { Mass = 1, Density = 1 };
                box.State.Assets = new RenderingAssets { Mesh = "PioneerWheel.bos" };
                //box.State.Assets = new RenderingAssets();
                //box.State.Assets.Mesh = "IRobot-Create.bos";
                //box.BoxShape.BoxState.TextureFileName = "IRobot-Create.bos";
                return InsertVisualEntity(box);
    
            }
    
            IEnumerator<ITask> SpawnedInsertVisualEntity(engine.VisualEntity visualEntity, ManualResetEvent insertEvent)
            {
                if (visualEntity == null)
                    yield break;
    
                var insertSimulationEntity = _simulationEnginePort.InsertSimulationEntity(visualEntity);
                yield return insertSimulationEntity.Choice();
    
                var fault1 = (Fault)insertSimulationEntity;
                if (fault1 != null)
                {
                    Trace.WriteLine(fault1);
                }
    
                var insert = (DefaultInsertResponseType)insertSimulationEntity;
                Trace.WriteLine(insert);
                insertEvent.Set();
                yield break;
            }
    
            private engine.VisualEntity InsertVisualEntity(engine.VisualEntity visualEntity)
            {
                //var insertResult = _simulationEnginePort.InsertSimulationEntity(visualEntity);
                var insertEvent = new ManualResetEvent(false);
                SpawnIterator(visualEntity, insertEvent, SpawnedInsertVisualEntity);
                insertEvent.WaitOne();
                return visualEntity;
            }
    
            void AddGround()
            {
                //// create a large horizontal plane, at zero elevation.
                var ground = new Microsoft.Robotics.Simulation.Engine.HeightFieldEntity(
    
                    "simple ground", // name
                    "03RamieSc.dds", // texture image
                    new MaterialProperties("ground",
                        0.2f, // restitution
                        0.5f, // dynamic friction
                        0.5f) // static friction
                    );
                Microsoft.Robotics.Simulation.Engine.SimulationEngine.GlobalInstancePort.Insert(ground);
            }
    
            /// <summary>Add a sky</summary>
            void AddSky()
            {
                //// Add a sky using a static texture. We will use the sky texture
                //// to do per pixel lighting on each simulation visual entity
                var sky = new Microsoft.Robotics.Simulation.Engine.SkyDomeEntity("skydome.dds", "sky_diff.dds");
                var skyDomeEntity = new SkyDomeEntity
                                        {
                                            VisualTexture = "skydome.dds",
                                            LightingTexture = "sky_diff.dds"
                                        };
                Microsoft.Robotics.Simulation.Engine.SimulationEngine.GlobalInstancePort.Insert(sky);
    
                //// Add a directional light to simulate the sun.
                var sun = new Microsoft.Robotics.Simulation.Engine.LightSourceEntity();
                sun.State.Name = "Sun";
    
                sun.Type = Microsoft.Robotics.Simulation.Engine.LightSourceEntityType.Directional;
                sun.Color = new Microsoft.Robotics.PhysicalModel.Vector4(0.8f, 0.8f, 0.8f, 1);
                //var sunResult = _simulationEnginePort.InsertSimulationEntity(sun);
                Microsoft.Robotics.Simulation.Engine.SimulationEngine.GlobalInstancePort.Insert(sun);
            }
    
            private void SetupCamera()
            {
                var view = new CameraView
                               {
                                   EyePosition = new Microsoft.Robotics.PhysicalModel.Vector3(0f, 10f, 0f),
                                   LookAtPoint = new Microsoft.Robotics.PhysicalModel.Vector3(0f, 0f, 0f),
                                   RenderMode = RenderMode.Combined
                               };
    
                SimulationEngine.GlobalInstancePort.Update(view);
    
            }
        }
    }
    
    
    
    Wednesday, February 24, 2010 9:54 PM
  • Hello Trevor,

    This might perhaps help track down the fault, stack track below.

    System.AccessViolationException was unhandled by user code
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      Source=PhysicsEngine
      StackTrace:
           at Microsoft.Robotics.Simulation.Physics.ActorContactReport.onContactNotify(ActorContactReport* , NxContactPair* pair, UInt32 events)
           at Microsoft.Robotics.Simulation.Physics.PhysicsEngine.GetPreviousFrameResults(Boolean waitForResults)
           at Microsoft.Robotics.Simulation.Engine.SimulationEngine.Update(GraphicsDevice device, Double appTime, Double elapsedTime, Double elapsedRealTime)
           at Microsoft.Robotics.Simulation.Engine.SimulationEngine.Application_Idle(Object sender, EventArgs e)
           at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at Microsoft.Robotics.Simulation.Engine.SimulationEngine.StartRenderLoop()
      InnerException:
    Sunday, February 28, 2010 11:11 AM
  • Hello Eric,

    I was unable to solve the problem, i eventully just created a app which would monitor the app that was getting the exception and restart it when it failed. Good luck, let me know if you manage to solve it.....

    Andrew.

    Saturday, July 10, 2010 5:40 PM