Skip to content

Commit

Permalink
sdl: sort imports names before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelk committed Dec 13, 2024
1 parent 0d5be41 commit 5928095
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gui/sdl/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/retroenv/retrogolib/gui"
)

// Setup initializes the SDL library and returns a render and cleanup function.
func Setup(backend gui.Backend) (guiRender func() (bool, error), guiCleanup func(), err error) {
dimensions := backend.Dimensions()

Expand All @@ -29,6 +30,7 @@ func Setup(backend gui.Backend) (guiRender func() (bool, error), guiCleanup func
return render, cleanup, nil
}

// setupSDL initializes the SDL library and creates the window, renderer, and texture.
func setupSDL(dimensions gui.Dimensions, backend gui.Backend) (uintptr, uintptr, uintptr, error) {
if err := setupLibrary(); err != nil {
return 0, 0, 0, fmt.Errorf("setting up SDL library: %w", err)
Expand Down Expand Up @@ -62,7 +64,7 @@ func setupSDL(dimensions gui.Dimensions, backend gui.Backend) (uintptr, uintptr,
return window, renderer, tex, nil
}

// renderSDL
// renderSDL renders the image to the SDL window.
func renderSDL(dimensions gui.Dimensions, backend gui.Backend, renderer uintptr, tex uintptr) (bool, error) {
var event event
for ret := PollEvent(&event); ret != 0; ret = PollEvent(&event) {
Expand Down
9 changes: 8 additions & 1 deletion gui/sdl/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ func setupLibrary() error {
return fmt.Errorf("loading SDL library: %w", err)
}

for name, ptr := range imports {
names := make([]string, 0, len(imports))
for name := range imports {
names = append(names, name)
}
sort.Strings(names)

Check failure on line 26 in gui/sdl/setup.go

View workflow job for this annotation

GitHub Actions / Coverage

undefined: sort

Check failure on line 26 in gui/sdl/setup.go

View workflow job for this annotation

GitHub Actions / Build (1.22)

undefined: sort

for _, name := range names {
ptr := imports[name]
if err := registerFunction(lib, name, ptr); err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion gui/sdl/setup_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sdl

import (
"fmt"
"sort"
"syscall"
)

Expand All @@ -18,7 +19,14 @@ func setupLibrary() error {
return fmt.Errorf("loading SDL library: %w", err)
}

for name, ptr := range imports {
names := make([]string, 0, len(imports))
for name := range imports {
names = append(names, name)
}
sort.Strings(names)

for _, name := range names {
ptr := imports[name]
if err := registerFunction(lib, name, ptr); err != nil {
return err
}
Expand Down

0 comments on commit 5928095

Please sign in to comment.