Fix some crashing issues in shadowdive
Tons of changes; can't exactly remember what. At least some debug printing and stuff.