Skip to content

Commit

Permalink
[Amadeusz Sławiński]
Browse files Browse the repository at this point in the history
Fix crashes with SDL on Linux due to delayed cursor setting.
  • Loading branch information
asvitkine committed Jun 18, 2012
1 parent a1f0283 commit be28a8e
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions BasiliskII/src/SDL/video_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ static int keycode_table[256]; // X keycode -> Mac keycode translation tabl
// SDL variables
static int screen_depth; // Depth of current screen
static SDL_Cursor *sdl_cursor; // Copy of Mac cursor
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors
static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK;
Expand Down Expand Up @@ -798,7 +797,6 @@ driver_window::driver_window(SDL_monitor_desc &m)
// Create cursor
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
SDL_SetCursor(sdl_cursor);
cursor_changed = false;
}
#else
// Hide cursor
Expand Down Expand Up @@ -1538,6 +1536,7 @@ void SDL_monitor_desc::switch_to_current_mode(void)
#ifdef SHEEPSHAVER
bool video_can_change_cursor(void)
{
#if defined(__APPLE__)
static char driver[] = "Quartz?";
static int quartzok = -1;

Expand All @@ -1556,6 +1555,9 @@ bool video_can_change_cursor(void)
}

return quartzok;
#else
return true;
#endif
}
#endif

Expand All @@ -1567,7 +1569,25 @@ bool video_can_change_cursor(void)
#ifdef SHEEPSHAVER
void video_set_cursor(void)
{
cursor_changed = true;
// Set new cursor image if it was changed
if (sdl_cursor) {
SDL_FreeCursor(sdl_cursor);
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
if (sdl_cursor) {
SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
SDL_SetCursor(sdl_cursor);
#ifdef WIN32
// XXX Windows apparently needs an extra mouse event to
// make the new cursor image visible
int visible = SDL_ShowCursor(-1);
if (visible) {
int x, y;
SDL_GetMouseState(&x, &y);
SDL_WarpMouse(x, y);
}
#endif
}
}
}
#endif

Expand Down Expand Up @@ -2239,30 +2259,6 @@ static inline void do_video_refresh(void)
// Update display
video_refresh();

#ifdef SHEEPSHAVER
// Set new cursor image if it was changed
if (cursor_changed && sdl_cursor) {
cursor_changed = false;
LOCK_EVENTS;
SDL_FreeCursor(sdl_cursor);
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
if (sdl_cursor) {
SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
SDL_SetCursor(sdl_cursor);
#ifdef WIN32
// XXX Windows apparently needs an extra mouse event to
// make the new cursor image visible
int visible = SDL_ShowCursor(-1);
if (visible) {
int x, y;
SDL_GetMouseState(&x, &y);
SDL_WarpMouse(x, y);
}
#endif
}
UNLOCK_EVENTS;
}
#endif

// Set new palette if it was changed
handle_palette_changes();
Expand Down

0 comments on commit be28a8e

Please sign in to comment.