diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 5e89705cf5a..7aed521c504 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -5763,11 +5763,16 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) /* are we an object material or data based? */ if (ob->colbits & 1<mesh->mat[i] = ob->mat[i]; - ob->mat[i]->id.us++; - origmesh->mat[i]->id.us--; + + if (ob->mat[i]) + ob->mat[i]->id.us++; + if (origmesh->mat[i]) + origmesh->mat[i]->id.us--; } else { - origmesh->mat[i]->id.us++; self->mesh->mat[i] = origmesh->mat[i]; + + if (origmesh->mat[i]) + origmesh->mat[i]->id.us++; } } }