Skip to content

Commit 566b724

Browse files
malashinveeableful
authored andcommitted
sdl: video, render: Update error handling; Add SetError() and INIT_EVENTS
1 parent b50c282 commit 566b724

File tree

6 files changed

+328
-370
lines changed

6 files changed

+328
-370
lines changed

BREAKING.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
### v0.2..master
44

5-
+ Renamed `Texture.GL_BindTexture()` and `Texture.GL_UnbindTexture()` to `Texture.GLBind()` and `Texture.GLUnbind()` respectively
5+
+ Renamed `Texture.GL_BindTexture()` to `Texture.GLBind()`
6+
+ Renamed `Texture.GL_UnbindTexture()` to `Texture.GLUnbind()`
67
+ Renamed `LoadWAV_RW()` to `LoadWAVRW()`
78
+ Renamed `TouchId` to `TouchID` in `MultiGestureEvent` struct
89
+ Renamed `Unicode` to `unused` in `Keysym` struct (must have been a typo)
@@ -53,10 +54,18 @@
5354
+ Renamed `QuickLoad_WAV()` to `QuickLoadWAV()`
5455
+ Renamed `QuickLoad_RAW()` to `QuickLoadRAW()`
5556
+ Moved error to the last return value in `ShowMessageBox()`
56-
+ Change Mutex, Sem, Cond to have methods instead of functions
57-
+ Merge `KeyUpEvent` and `KeyDownEvent` into `KeyboardEvent`
57+
+ Changed Mutex, Sem, Cond to have methods instead of functions
58+
+ Merged `KeyUpEvent` and `KeyDownEvent` into `KeyboardEvent`
5859
+ Haptic functions now return bool and/or error instead of int
59-
+ Change `GameControllerMapping()` into `GameController.Mapping()`
60+
+ Changed `GameControllerMapping()` into `GameController.Mapping()`
61+
+ `GetDisplayName()` returns (string, error) instead of string
62+
+ `GetCurrentVideoDriver()` returns (string, error) instead of string
63+
+ `Window.Destroy()` returns error
64+
+ `Window.GetID()` returns (uint32, error) instead of uint32
65+
+ `GetNumRenderDrivers()` returns (int, error) instead of int
66+
+ `GetRenderDriverInfo()` returns (int, error) instead of int
67+
+ `Texture.Destroy()` returns error
68+
+ `Renderer.Destroy()` returns error
6069

6170
- Unexported `Padding` in `AudioSpec` struct
6271
- Unexported `goHintCallback`

sdl/error.go

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package sdl
22

3+
/*
4+
#include "sdl_wrapper.h"
5+
6+
void GoSetError(const char *fmt) {
7+
SDL_SetError("%s", fmt);
8+
}
9+
*/
310
// #include "sdl_wrapper.h"
411
import "C"
512
import "errors"
@@ -35,6 +42,16 @@ func GetError() error {
3542
return nil
3643
}
3744

45+
// SetError set the SDL error message.
46+
// (https://wiki.libsdl.org/SDL_SetError)
47+
func SetError(err error) {
48+
if err != nil {
49+
C.GoSetError(C.CString(err.Error()))
50+
return
51+
}
52+
C.GoSetError(nil)
53+
}
54+
3855
// ClearError clears any previous error message.
3956
// (https://wiki.libsdl.org/SDL_ClearError)
4057
func ClearError() {

sdl/events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ func goEvent(cevent *CEvent) Event {
627627
return (*DollarGestureEvent)(unsafe.Pointer(cevent))
628628
case DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE:
629629
e := (*tDropEvent)(unsafe.Pointer(cevent))
630-
event := DropEvent{Type: e.Type, Timestamp: e.Timestamp, File: string(C.GoString((*C.char)(e.File))), WindowID: e.WindowID}
630+
event := DropEvent{Type: e.Type, Timestamp: e.Timestamp, File: C.GoString((*C.char)(e.File)), WindowID: e.WindowID}
631631
C.SDL_free(e.File)
632632
return &event
633633
case RENDER_TARGETS_RESET, RENDER_DEVICE_RESET:

0 commit comments

Comments
 (0)