From 8c0d9ec5d0c8e7744ed618992aace0d792e487f3 Mon Sep 17 00:00:00 2001 From: Lilis Iskandar Date: Mon, 9 Jul 2018 21:50:57 +0800 Subject: [PATCH] sdl: error: Fix crash on certain Windows environment Apparently caused by sdl.SetError(nil) but it doesn't always happen. See https://github.com/veandco/go-sdl2/issues/340 Signed-off-by: Lilis Iskandar --- sdl/error.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdl/error.go b/sdl/error.go index 1d281ac1..9904c09d 100644 --- a/sdl/error.go +++ b/sdl/error.go @@ -6,11 +6,14 @@ package sdl void GoSetError(const char *fmt) { SDL_SetError("%s", fmt); } + */ // #include "sdl_wrapper.h" import "C" import "errors" +var emptyCString *C.char = C.CString("") + // SDL error codes with their corresponding predefined strings. const ( ENOMEM ErrorCode = C.SDL_ENOMEM // out of memory @@ -49,7 +52,7 @@ func SetError(err error) { C.GoSetError(C.CString(err.Error())) return } - C.GoSetError(nil) + C.GoSetError(emptyCString) } // ClearError clears any previous error message.