Merge pull request #1214 from assimp/issue_1211

closes https://github.com/assimp/assimp/issues/1211: defensice handling
pull/1217/head
Kim Kulling 2017-03-23 20:36:01 +01:00 committed by GitHub
commit 63485bdd26
1 changed files with 38 additions and 34 deletions

View File

@ -119,7 +119,8 @@ def _init(self, target = None, parent = None):
if m == 'mName':
obj = self.mName
target.name = str(obj.data.decode("utf-8"))
uni = unicode(obj.data, errors='ignore')
target.name = str( uni )
target.__class__.__repr__ = lambda x: str(x.__class__) + "(" + x.name + ")"
target.__class__.__str__ = lambda x: x.name
continue
@ -439,7 +440,8 @@ def _get_properties(properties, length):
for p in [properties[i] for i in range(length)]:
#the name
p = p.contents
key = (str(p.mKey.data.decode("utf-8")).split('.')[1], p.mSemantic)
uni = unicode(p.mKey.data, errors='ignore')
key = (str(uni).split('.')[1], p.mSemantic)
#the data
from ctypes import POINTER, cast, c_int, c_float, sizeof
@ -447,7 +449,9 @@ def _get_properties(properties, length):
arr = cast(p.mData, POINTER(c_float * int(p.mDataLength/sizeof(c_float)) )).contents
value = [x for x in arr]
elif p.mType == 3: #string can't be an array
value = cast(p.mData, POINTER(structs.MaterialPropertyString)).contents.data.decode("utf-8")
uni = unicode(cast(p.mData, POINTER(structs.MaterialPropertyString)).contents.data, errors='ignore')
value = uni
elif p.mType == 4:
arr = cast(p.mData, POINTER(c_int * int(p.mDataLength/sizeof(c_int)) )).contents
value = [x for x in arr]