Shut down emulation when the game exits.

Fixes #5421.