Skip to content

Commit

Permalink
Fix WorkingMesh name termination; Fix GetTriangleRange not respecting…
Browse files Browse the repository at this point in the history
… subMeshCount
  • Loading branch information
amirebrahimi committed Aug 13, 2021
1 parent cbb89da commit de9b143
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Editor/AutoLOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ static void PreferencesGUI()
if (meshSimplifierType != null && typeof(IMeshSimplifier).IsAssignableFrom(meshSimplifierType))
{
if (s_SimplifierPreferences == null || s_SimplifierPreferences.GetType() != meshSimplifierType)
s_SimplifierPreferences = (IPreferences)Activator.CreateInstance(meshSimplifierType);
s_SimplifierPreferences = Activator.CreateInstance(meshSimplifierType) as IPreferences;

if (s_SimplifierPreferences != null)
{
Expand Down
17 changes: 11 additions & 6 deletions Runtime/Helpers/WorkingMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,23 @@ int submeshOffsetCount

public string name
{
get { return Encoding.UTF8.GetString(m_Name.ToArray()); }
get
{
var bytes = m_Name.Slice(0, m_NameLength).ToArray();
return Encoding.UTF8.GetString(bytes);
}
set
{
if (value == null)
value = string.Empty;

var bytes = Encoding.UTF8.GetBytes(value);
var length = Mathf.Min(bytes.Length, k_MaxNameSize);
m_Name.Slice(0, length).CopyFrom(bytes);
m_NameLength = Mathf.Min(bytes.Length, k_MaxNameSize);
m_Name.Slice(0, m_NameLength).CopyFrom(bytes);
}
}
NativeArray<byte> m_Name;
int m_NameLength;

// This data does not cross the job threshold, so if it needs to be read back, then it will need to be
// in a NativeArray or some other type of NativeContainer
Expand Down Expand Up @@ -437,7 +442,7 @@ public void SetTriangles(int[] triangles, int submesh)

public int[] GetTriangles(int submesh)
{
if (submesh < m_SubmeshOffset.Length)
if (submesh < subMeshCount)
{
var start = 0;
var stop = 0;
Expand All @@ -453,11 +458,11 @@ public int[] GetTriangles(int submesh)

void GetTriangleRange(int submesh, out int start, out int stop)
{
if (submesh < m_SubmeshOffset.Length)
if (submesh < subMeshCount)
{
start = m_SubmeshOffset[submesh];
stop = trianglesCount;
if (submesh < m_SubmeshOffset.Length - 1)
if (submesh < subMeshCount - 1)
stop = m_SubmeshOffset[submesh + 1];

return;
Expand Down

0 comments on commit de9b143

Please sign in to comment.