Search Unity

Physics.OverlapSphereNonAlloc throws System.AcessViolationException

Discussion in 'VR' started by vinnie-vivace, May 16, 2017.

  1. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    40
    yo peoples.

    Below a very basic script, attached to a game object in a scene with number of box colliders. Run in the editor the script works correctly, drawing a debug line to the detected colliders, and outputing the number of collisions detected to the console.

    When I deploy the same scene to the Hololens, I get an exception.

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

    StackTrace " at UnityEngineProxy.InternalCalls.PInvokeCalls.Physics_CUSTOM_INTERNAL_CALL_OverlapSphereNonAlloc(IntPtr param_0, Single param_1, Int64 param_2, Int32 param_3, Int32 param_4, Int64& outExceptionHandle)\r\n at UnityEngineProxy.InternalCalls.Physics_CUSTOM_INTERNAL_CALL_OverlapSphereNonAlloc(IntPtr position, Single radius, Object results, Int32 layerMask, Int32 queryTriggerInteraction)\r\n at UnityEngine.Physics.INTERNAL_CALL_OverlapSphereNonAlloc(Vector3& position, Single radius, Collider[] results, Int32 layerMask, QueryTriggerInteraction queryTriggerInteraction)\r\n at UnityEngine.Physics.OverlapSphereNonAlloc(Vector3 position, Single radius, Collider[] results)\r\n at Test.Update()\r\n at Test.$Invoke6Update(Int64 instance, Int64* args)\r\n at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)" string


    Any thoughts, suggestions etc would be much appreciated.

    cheers
    Vinnie

    Code (CSharp):
    1. public class Test : MonoBehaviour {
    2.  
    3.     private Collider[] overlapResults = new Collider[10];
    4.  
    5.     public int NumberOfCollisions = 0;
    6.  
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.      
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update () {
    15.         NumberOfCollisions = Physics.OverlapSphereNonAlloc(transform.position, 10f, overlapResults);
    16.  
    17.         for (int i = 0; i < NumberOfCollisions; i++)
    18.         {
    19.             Debug.DrawLine(transform.position, overlapResults[i].transform.position, Color.red);
    20.         }
    21.  
    22.         Debug.Log("collisions " + this.NumberOfCollisions);
    23.     }
    24. }
     
    Last edited: May 16, 2017
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    The API call Debug.DrawLine doesn't work on the HoloLens because it is a gizmo, these don't render on the HoloLens. My suggestion is to do a Physics.Raycast from the HoloLens camera, then draw a line using the line renderer from the HoloLens camera to the Ray Cast Hit point.

    Let me know if you have questions.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    vinnie-vivace likes this.
  4. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    40
    Thanks for that, the Exception is thrown before the Debug gizmo code on Line 15.

    Cheers
     
  5. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    40
  6. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    40
    I can confirm 5.6.1 fixes this error.