Fix crash when switching to another buffer after deleting a buffer.

The event was returning the index of a buffer that did not exist and a NullPointerException was being thrown when attempting to call member methods on the non-existent buffer.  This inserts a check to see if the buffer is null before doing anything to it.