Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

NativeSlice<U> SliceWithStride method problem

Discussion in 'Scripting' started by sniperbat, Aug 7, 2020.

  1. sniperbat

    sniperbat

    Joined:
    Aug 25, 2014
    Posts:
    7
    "NativeSlice<U> SliceWithStride" method looks like below, but I think there are some error process.
    Code (CSharp):
    1.  
    2. // Convert NativeSlice<T> to a new NativeSlice<U> to Contain type U element, start from "offset"。
    3. public unsafe NativeSlice<U> SliceWithStride<U>(int offset) where U : struct
    4. {
    5.       NativeSlice<U> nativeSlice;
    6.       nativeSlice.m_Buffer = this.m_Buffer + offset;
    7.       nativeSlice.m_Stride = this.m_Stride; // Use old type stride?? or should use size of Type U
    8.       nativeSlice.m_Length = this.m_Length; // Length should recalculate by Type U too !
    9.       if (offset < 0)
    10.         throw new ArgumentOutOfRangeException(nameof (offset), "SliceWithStride offset must be >= 0");
    11.       if (offset + UnsafeUtility.SizeOf<U>() > UnsafeUtility.SizeOf<T>())
    12.         throw new ArgumentException("SliceWithStride sizeof(U) + offset must be <= sizeof(T)", nameof (offset));
    13.       nativeSlice.m_MinIndex = this.m_MinIndex;
    14.       nativeSlice.m_MaxIndex = this.m_MaxIndex;
    15.       nativeSlice.m_Safety = this.m_Safety;
    16.       return nativeSlice;
    17. }
    18.  


    Pls check it. Thx!

    Best regards
     
    Last edited: Aug 7, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    This isn't actually anything another person can act upon.

    How to report problems productively in the Unity3D forums:

    http://plbm.com/?p=220

    Help us to help you.