Fix crash when deleting entity.
Merge pull request #565 from fodinabor/entityDelFix

Fix crash when deleting entity.