Handle invalid frame_or_window slots in tty input events (Bug#78966)
* src/frame.c (make_terminal_frame): Initialize terminal's
top_frame slot if it has not been set up yet (Bug#78966).
* src/keyboard.c (kbd_buffer_get_event): Do not assume that the
event's frame_or_window slot always produces a valid frame
(Bug#78966).
(tty_read_avail_input): Try to make sure that the input event we
create has a valid frame_or_window slot (Bug#78966). Add assertion
to that purpose.
(cherry picked from commit
2fc402cb0bb62f3c401528246742501a8d42bf14)