Exemple #1
0
        /// <summary>
        /// This is called from within simulate but outside the locked portion
        /// We need to do our own locking here
        /// Essentially, we need to remove the prim from our space segment, whatever segment it's in.
        ///
        /// If there are no more prim in the segment, we need to empty (spacedestroy)the segment and reclaim memory
        /// that the space was using.
        /// </summary>
        /// <param name="prim"></param>
        public void RemovePrimThreadLocked(OdePrim prim)
        {
//Console.WriteLine("RemovePrimThreadLocked " +  prim.m_primName);
            lock (prim)
            {
                remCollisionEventReporting(prim);
                lock (ode)
                {
                    if (prim.prim_geom != IntPtr.Zero)
                    {
                        prim.ResetTaints();

                        if (prim.IsPhysical)
                        {
                            prim.disableBody();
                            if (prim.childPrim)
                            {
                                prim.childPrim = false;
                                prim.Body = IntPtr.Zero;
                                prim.m_disabled = true;
                                prim.IsPhysical = false;
                            }


                        }
                        // we don't want to remove the main space

                        // If the geometry is in the targetspace, remove it from the target space
                        //m_log.Warn(prim.m_targetSpace);

                        //if (prim.m_targetSpace != IntPtr.Zero)
                        //{
                        //if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
                        //{

                        //if (d.GeomIsSpace(prim.m_targetSpace))
                        //{
                        //waitForSpaceUnlock(prim.m_targetSpace);
                        //d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
                        prim.m_targetSpace = IntPtr.Zero;
                        //}
                        //else
                        //{
                        // m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
                        //((OdePrim)prim).m_targetSpace.ToString());
                        //}

                        //}
                        //}
                        //m_log.Warn(prim.prim_geom);
                        try
                        {
                            if (prim.prim_geom != IntPtr.Zero)
                            {
                                d.GeomDestroy(prim.prim_geom);
                                prim.prim_geom = IntPtr.Zero;
                            }
                            else
                            {
                                m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene");
                            }
                        }
                        catch (AccessViolationException)
                        {
                            m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed.");
                        }
                        lock (_prims)
                        _prims.Remove(prim);

                        //If there are no more geometries in the sub-space, we don't need it in the main space anymore
                        //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
                        //{
                        //if (prim.m_targetSpace != null)
                        //{
                        //if (d.GeomIsSpace(prim.m_targetSpace))
                        //{
                        //waitForSpaceUnlock(prim.m_targetSpace);
                        //d.SpaceRemove(space, prim.m_targetSpace);
                        // free up memory used by the space.
                        //d.SpaceDestroy(prim.m_targetSpace);
                        //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
                        //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
                        //}
                        //else
                        //{
                        //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
                        //((OdePrim) prim).m_targetSpace.ToString());
                        //}
                        //}
                        //}

                        if (SupportsNINJAJoints)
                        {
                            RemoveAllJointsConnectedToActorThreadLocked(prim);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// This is called from within simulate but outside the locked portion
        /// We need to do our own locking here
        /// (Note: As of 20110801 this no longer appears to be true - this is being called within lock (odeLock) in
        /// Simulate() -- justincc).
        ///
        /// Essentially, we need to remove the prim from our space segment, whatever segment it's in.
        ///
        /// If there are no more prim in the segment, we need to empty (spacedestroy)the segment and reclaim memory
        /// that the space was using.
        /// </summary>
        /// <param name="prim"></param>
        internal void RemovePrimThreadLocked(OdePrim prim)
        {
//            m_log.DebugFormat("[ODE SCENE]: Removing physical prim {0} {1}", prim.Name, prim.LocalID);

            lock (prim)
            {
                RemoveCollisionEventReporting(prim);

                if (prim.prim_geom != IntPtr.Zero)
                {
                    prim.ResetTaints();

                    if (prim.IsPhysical)
                    {
                        prim.disableBody();
                        if (prim.childPrim)
                        {
                            prim.childPrim = false;
                            prim.Body = IntPtr.Zero;
                            prim.m_disabled = true;
                            prim.IsPhysical = false;
                        }


                    }
                    // we don't want to remove the main space

                    // If the geometry is in the targetspace, remove it from the target space
                    //m_log.Warn(prim.m_targetSpace);

                    //if (prim.m_targetSpace != IntPtr.Zero)
                    //{
                    //if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
                    //{

                    //if (d.GeomIsSpace(prim.m_targetSpace))
                    //{
                    //waitForSpaceUnlock(prim.m_targetSpace);
                    //d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
                    prim.m_targetSpace = IntPtr.Zero;
                    //}
                    //else
                    //{
                    // m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
                    //((OdePrim)prim).m_targetSpace.ToString());
                    //}

                    //}
                    //}
                    //m_log.Warn(prim.prim_geom);

                    if (!prim.RemoveGeom())
                        m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene");

                    lock (_prims)
                        _prims.Remove(prim);

                    //If there are no more geometries in the sub-space, we don't need it in the main space anymore
                    //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
                    //{
                    //if (prim.m_targetSpace != null)
                    //{
                    //if (d.GeomIsSpace(prim.m_targetSpace))
                    //{
                    //waitForSpaceUnlock(prim.m_targetSpace);
                    //d.SpaceRemove(space, prim.m_targetSpace);
                    // free up memory used by the space.
                    //d.SpaceDestroy(prim.m_targetSpace);
                    //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
                    //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
                    //}
                    //else
                    //{
                    //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" +
                    //((OdePrim) prim).m_targetSpace.ToString());
                    //}
                    //}
                    //}

                    if (SupportsNINJAJoints)
                        RemoveAllJointsConnectedToActorThreadLocked(prim);
                }
            }
        }