Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault in player-sdl #2062

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tic80.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ typedef struct

TIC80_API tic80* tic80_create(s32 samplerate, tic80_pixel_color_format format);
TIC80_API void tic80_load(tic80* tic, void* cart, s32 size);
TIC80_API void tic80_tick(tic80* tic, tic80_input input);
TIC80_API void tic80_tick(tic80* tic, tic80_input input, u64 (*counter)(), u64 (*freq)());
TIC80_API void tic80_sound(tic80* tic);
TIC80_API void tic80_delete(tic80* tic);

Expand Down
2 changes: 1 addition & 1 deletion src/system/libretro/tic80_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ void tic80_libretro_update(tic80* game)
tic80_libretro_update_keyboard(&state->input.keyboard);

// Update the game state.
tic80_tick(game, state->input);
tic80_tick(game, state->input, NULL, NULL);
tic80_sound(game);
}

Expand Down
12 changes: 11 additions & 1 deletion src/system/sdl/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ static void onExit()
state.quit = true;
}

static u64 tic_sys_counter_get()
{
return SDL_GetPerformanceCounter();
}

static u64 tic_sys_freq_get()
{
return SDL_GetPerformanceFrequency();
}

static void audioCallback(void* userdata, u8* stream, s32 len)
{
SDL_LockMutex(state.mutex);
Expand Down Expand Up @@ -164,7 +174,7 @@ s32 runCart(void* cart, s32 size)

SDL_LockMutex(state.mutex);
{
tic80_tick(tic, input);
tic80_tick(tic, input, tic_sys_counter_get, tic_sys_freq_get);
}
SDL_UnlockMutex(state.mutex);

Expand Down
7 changes: 4 additions & 3 deletions src/tic.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size)
tic_api_reset(mem);
}

TIC80_API void tic80_tick(tic80* tic, tic80_input input)
TIC80_API void tic80_tick(tic80* tic, tic80_input input, u64 (*counter)(), u64 (*freq)())
{
tic_mem* mem = (tic_mem*)tic;

Expand All @@ -77,13 +77,14 @@ TIC80_API void tic80_tick(tic80* tic, tic80_input input)
.trace = onTrace,
.exit = onExit,
.data = tic,
.start = 0
.start = 0,
.counter = counter,
.freq = freq
};

tic_core_tick_start(mem);
tic_core_tick(mem, &tickData);
tic_core_tick_end(mem);

tic_core_blit(mem);
}

Expand Down