Lol, I wish I had seen this yesterday. I don't know if THIS is why you flew into a tree, but one of my guys did this with someone else's drones on a structure scan.
You need to edit the failsafe behavior first, depending on the density and size of the building. Otherwise, you lose contact when flying around the building, and the drone tries to fly back to the home position.
Exactly what happened, except it hit 10% battery while hovering about 5 feet from me inches off the ground, went into return to home, which was a tree.