Making texture manager code more crash resistant
Fixing various crash bugs