Fixed a bug which caused a material to be deleted twice (A mesh could hold two raw pointers to the same material and when they were converted to a shared pointer, they both were deleted).