Skip to content

Commit f72e5df

Browse files
dv1x3rK0lb3
authored andcommitted
fix: skip read_vertex_data when VertexData is empty
fix: correct channelMask bit parsing in get_channels
1 parent fed451f commit f72e5df

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

UnityPy/helpers/MeshHelper.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@ def process(self):
159159
if mesh.m_Use16BitIndices is not None:
160160
self.m_Use16BitIndices = bool(mesh.m_Use16BitIndices)
161161
elif (
162-
self.version >= (2017, 4)
162+
(self.version >= (2017, 4))
163163
or
164164
# version == (2017, 3, 1) & patched - px string
165-
self.version[:2] == (2017, 3)
166-
and mesh.m_MeshCompression == 0
165+
(self.version[:2] == (2017, 3) and mesh.m_MeshCompression == 0)
167166
):
168167
self.m_Use16BitIndices = mesh.m_IndexFormat == 0
169168
self.copy_from_mesh()
@@ -292,10 +291,10 @@ def get_channels(self, m_Streams: list[StreamInfo]) -> list[ChannelInfo]:
292291
for _ in range(6)
293292
]
294293
for s, m_Stream in enumerate(m_Streams):
295-
channelMask = bytearray(m_Stream.channelMask) # BitArray
294+
channelMask = m_Stream.channelMask # uint
296295
offset = 0
297296
for i in range(6):
298-
if channelMask[i]:
297+
if channelMask & (1 << i):
299298
m_Channel = m_Channels[i]
300299
m_Channel.stream = s
301300
m_Channel.offset = offset
@@ -326,6 +325,12 @@ def read_vertex_data(self, m_Channels: list[ChannelInfo], m_Streams: list[Stream
326325
if m_VertexData is None:
327326
return
328327

328+
# could be empty for fully compressed meshes
329+
# in that case data will be read from CompressedMesh via decompress_compressed_mesh
330+
# also avoids a crash in UnityPyBoost.unpack_vertexdata with empty data
331+
if m_VertexData.m_VertexCount == 0 or not m_VertexData.m_DataSize:
332+
return
333+
329334
self.m_VertexCount = m_VertexCount = m_VertexData.m_VertexCount
330335
# m_VertexDataRaw = m_VertexData.m_DataSize
331336

0 commit comments

Comments
 (0)