Fixed bug 3451 - Raspberry Pi Raspbian SDL_assert triggered sometimes at RPI_WarpMouseGlobal

Eric wing

Sometimes an SDL_assert triggers at RPI_WarpMouseGlobal
src/video/raspberry/SDL_rpimouse.c:232 'update'.

It doesn't always reproduce, but it seems to happen when you really bog down the system and the event loop can't update for awhile.


The first time I hit this, I wasn't even using the mouse. I don't call any warp mouse functions either.


I can usually reproduce with a simple program that runs an expensive blocking CPU series of functions which blocks the main loop until complete (can be up to 10 seconds).

Sometimes this assertion gets triggered after that. I'm not sure if
they are related or coincidental.


Disabling the SDL_asserts when compiling SDL will avoid this problem. I actually haven't seen any problems with the mouse when I do this.

On a Raspberry Pi 2 running Raspbian Jessie.
This commit is contained in:
Sam Lantinga 2016-10-13 04:53:01 -07:00
parent c490b54e08
commit f94bd05736
1 changed files with 68 additions and 61 deletions

View File

@ -87,17 +87,17 @@ RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
curdata->h = surface->h; curdata->h = surface->h;
/* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */ /* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */
curdata->resource = vc_dispmanx_resource_create( VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy ); curdata->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy);
SDL_assert(curdata->resource); SDL_assert(curdata->resource);
vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h); vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
/* A note from Weston: /* A note from Weston:
* vc_dispmanx_resource_write_data() ignores ifmt, * vc_dispmanx_resource_write_data() ignores ifmt,
* rect.x, rect.width, and uses stride only for computing * rect.x, rect.width, and uses stride only for computing
* the size of the transfer as rect.height * stride. * the size of the transfer as rect.height * stride.
* Therefore we can only write rows starting at x=0. * Therefore we can only write rows starting at x=0.
*/ */
ret = vc_dispmanx_resource_write_data( curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect ); ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect);
SDL_assert ( ret == DISPMANX_SUCCESS ); SDL_assert (ret == DISPMANX_SUCCESS);
cursor->driverdata = curdata; cursor->driverdata = curdata;
@ -126,15 +126,15 @@ RPI_ShowCursor(SDL_Cursor * cursor)
if (cursor == NULL) { if (cursor == NULL) {
/* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */ /* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */
if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) { if (mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata; curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element > DISPMANX_NO_HANDLE) { if (curdata->element > DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 ); update = vc_dispmanx_update_start(10);
SDL_assert( update ); SDL_assert(update);
ret = vc_dispmanx_element_remove( update, curdata->element ); ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync( update ); ret = vc_dispmanx_update_submit_sync(update);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
curdata->element = DISPMANX_NO_HANDLE; curdata->element = DISPMANX_NO_HANDLE;
} }
} }
@ -161,13 +161,13 @@ RPI_ShowCursor(SDL_Cursor * cursor)
} }
if (curdata->element == DISPMANX_NO_HANDLE) { if (curdata->element == DISPMANX_NO_HANDLE) {
vc_dispmanx_rect_set( &src_rect, 0, 0, curdata->w << 16, curdata->h << 16 ); vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h); vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
update = vc_dispmanx_update_start( 10 ); update = vc_dispmanx_update_start(10);
SDL_assert( update ); SDL_assert(update);
curdata->element = vc_dispmanx_element_add( update, curdata->element = vc_dispmanx_element_add(update,
data->dispman_display, data->dispman_display,
SDL_RPI_MOUSELAYER, // layer SDL_RPI_MOUSELAYER, // layer
&dst_rect, &dst_rect,
@ -176,10 +176,10 @@ RPI_ShowCursor(SDL_Cursor * cursor)
DISPMANX_PROTECTION_NONE, DISPMANX_PROTECTION_NONE,
&alpha, &alpha,
DISPMANX_NO_HANDLE, // clamp DISPMANX_NO_HANDLE, // clamp
VC_IMAGE_ROT0 ); VC_IMAGE_ROT0);
SDL_assert( curdata->element > DISPMANX_NO_HANDLE); SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
ret = vc_dispmanx_update_submit_sync( update ); ret = vc_dispmanx_update_submit_sync(update);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
} }
return 0; return 0;
@ -198,17 +198,17 @@ RPI_FreeCursor(SDL_Cursor * cursor)
if (curdata != NULL) { if (curdata != NULL) {
if (curdata->element != DISPMANX_NO_HANDLE) { if (curdata->element != DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 ); update = vc_dispmanx_update_start(10);
SDL_assert( update ); SDL_assert(update);
ret = vc_dispmanx_element_remove( update, curdata->element ); ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync( update ); ret = vc_dispmanx_update_submit_sync(update);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
} }
if (curdata->resource != DISPMANX_NO_HANDLE) { if (curdata->resource != DISPMANX_NO_HANDLE) {
ret = vc_dispmanx_resource_delete( curdata->resource ); ret = vc_dispmanx_resource_delete(curdata->resource);
SDL_assert( ret == DISPMANX_SUCCESS ); SDL_assert(ret == DISPMANX_SUCCESS);
} }
SDL_free(cursor->driverdata); SDL_free(cursor->driverdata);
@ -235,11 +235,20 @@ RPI_WarpMouseGlobal(int x, int y)
VC_RECT_T src_rect; VC_RECT_T src_rect;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) { if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
return 0;
}
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata; curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element != DISPMANX_NO_HANDLE) { if (curdata->element == DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 ); return 0;
SDL_assert( update ); }
update = vc_dispmanx_update_start(10);
if (!update) {
return 0;
}
src_rect.x = 0; src_rect.x = 0;
src_rect.y = 0; src_rect.y = 0;
src_rect.width = curdata->w << 16; src_rect.width = curdata->w << 16;
@ -259,17 +268,15 @@ RPI_WarpMouseGlobal(int x, int y)
&src_rect, &src_rect,
DISPMANX_NO_HANDLE, DISPMANX_NO_HANDLE,
DISPMANX_NO_ROTATE); DISPMANX_NO_ROTATE);
if (ret != DISPMANX_SUCCESS ) { if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_element_change_attributes() failed"); return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
} }
/* Submit asynchronously, otherwise the peformance suffers a lot */ /* Submit asynchronously, otherwise the peformance suffers a lot */
ret = vc_dispmanx_update_submit( update, 0, NULL ); ret = vc_dispmanx_update_submit(update, 0, NULL);
if (ret != DISPMANX_SUCCESS ) { if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_update_submit() failed"); return SDL_SetError("vc_dispmanx_update_submit() failed");
} }
}
}
return 0; return 0;
} }