The program is attempting to change the window title without checking if the window exists yet. This in itself would be no more than a cosmetic problem, except that the code is temporarily borrowing the X server connection from SDL (taking advantage of an advanced, semi-documented feature of the library). SDL does not have code to properly handle the error event that results from the unexpected invalid request, and fails to recover properly.
FIX:
The fix is simply to add a test to avoid making the X request if the window ID is still zero. The existing code already has a fallback for changing the title using the standard SDL1.2 API if the X11 API is unusable, so the window title will still get set with this change.