Its not entirely surprising that you get a window system error when you keep restarting the window manager. Any request for window management services while it is stopped will fail. GDK (the low level component of GTK) will then fail and will exit the program and there is nothing the application (Geany) can do about it.
Please let me know if you need any additional information. I'm happy to help. Thank you.
You could try following the advice the error message gave you and post the results of a backtrace here but I doubt there is much we can do about it.