GRIM: Fix deleting material when it is still needed
Merge pull request #1142 from klusark/mat

GRIM: Fix deleting material when it is still needed