fix win32 crash while click close button.
fix close crash in linux and mac
Merge pull request #5793 from koowolf/win32_crash

Crash while clicking close button on desktop platforms