Why is the font getting created and loaded on every cycle in the main loop? It should be created and loaded before the loop so it only gets loaded once. It wouldn't hurt to take the text object out of the loop too
That's because a still equals true. If you do what Hapax said then it should solve the problem. Just because the window is gone, it doesn't mean that all loops will automatically stop. If you want to end your program using window.close(), you need to put window.isOpen() as your loop condition.
A quick google just told me that the error is usually when you are accessing part of an array that doesn't exist (is out of bounds). I couldn't see that in the code you'd given but I know you omitted some things so it might be in there. Basically the error means you are accessing something that doesn't exist when you access it.Problem is not solved.
EDIT: I wasn't sure whether you had completely solved the problem or whether it had just stopped coming up for the moment and this seemed like useful information so it doesn't happen again.