Making texture manager code more crash resistant