Fix bug with render loop not terminating on state change