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

View file

@ -87,17 +87,17 @@ RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
curdata->h = surface->h;
/* 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);
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:
* vc_dispmanx_resource_write_data() ignores ifmt,
* rect.x, rect.width, and uses stride only for computing
* the size of the transfer as rect.height * stride.
* 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 );
SDL_assert ( ret == DISPMANX_SUCCESS );
ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect);
SDL_assert (ret == DISPMANX_SUCCESS);
cursor->driverdata = curdata;
@ -126,15 +126,15 @@ RPI_ShowCursor(SDL_Cursor * cursor)
if (cursor == NULL) {
/* 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;
if (curdata->element > DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 );
SDL_assert( update );
ret = vc_dispmanx_element_remove( update, curdata->element );
SDL_assert( ret == DISPMANX_SUCCESS );
ret = vc_dispmanx_update_submit_sync( update );
SDL_assert( ret == DISPMANX_SUCCESS );
update = vc_dispmanx_update_start(10);
SDL_assert(update);
ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync(update);
SDL_assert(ret == DISPMANX_SUCCESS);
curdata->element = DISPMANX_NO_HANDLE;
}
}
@ -161,13 +161,13 @@ RPI_ShowCursor(SDL_Cursor * cursor)
}
if (curdata->element == DISPMANX_NO_HANDLE) {
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(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
update = vc_dispmanx_update_start( 10 );
SDL_assert( update );
update = vc_dispmanx_update_start(10);
SDL_assert(update);
curdata->element = vc_dispmanx_element_add( update,
curdata->element = vc_dispmanx_element_add(update,
data->dispman_display,
SDL_RPI_MOUSELAYER, // layer
&dst_rect,
@ -176,10 +176,10 @@ RPI_ShowCursor(SDL_Cursor * cursor)
DISPMANX_PROTECTION_NONE,
&alpha,
DISPMANX_NO_HANDLE, // clamp
VC_IMAGE_ROT0 );
SDL_assert( curdata->element > DISPMANX_NO_HANDLE);
ret = vc_dispmanx_update_submit_sync( update );
SDL_assert( ret == DISPMANX_SUCCESS );
VC_IMAGE_ROT0);
SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
ret = vc_dispmanx_update_submit_sync(update);
SDL_assert(ret == DISPMANX_SUCCESS);
}
return 0;
@ -198,17 +198,17 @@ RPI_FreeCursor(SDL_Cursor * cursor)
if (curdata != NULL) {
if (curdata->element != DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 );
SDL_assert( update );
ret = vc_dispmanx_element_remove( update, curdata->element );
SDL_assert( ret == DISPMANX_SUCCESS );
ret = vc_dispmanx_update_submit_sync( update );
SDL_assert( ret == DISPMANX_SUCCESS );
update = vc_dispmanx_update_start(10);
SDL_assert(update);
ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync(update);
SDL_assert(ret == DISPMANX_SUCCESS);
}
if (curdata->resource != DISPMANX_NO_HANDLE) {
ret = vc_dispmanx_resource_delete( curdata->resource );
SDL_assert( ret == DISPMANX_SUCCESS );
ret = vc_dispmanx_resource_delete(curdata->resource);
SDL_assert(ret == DISPMANX_SUCCESS);
}
SDL_free(cursor->driverdata);
@ -235,41 +235,48 @@ RPI_WarpMouseGlobal(int x, int y)
VC_RECT_T src_rect;
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element != DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start( 10 );
SDL_assert( update );
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = curdata->w << 16;
src_rect.height = curdata->h << 16;
dst_rect.x = x;
dst_rect.y = y;
dst_rect.width = curdata->w;
dst_rect.height = curdata->h;
if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
return 0;
}
ret = vc_dispmanx_element_change_attributes(
update,
curdata->element,
0,
0,
0,
&dst_rect,
&src_rect,
DISPMANX_NO_HANDLE,
DISPMANX_NO_ROTATE);
if (ret != DISPMANX_SUCCESS ) {
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
}
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element == DISPMANX_NO_HANDLE) {
return 0;
}
/* Submit asynchronously, otherwise the peformance suffers a lot */
ret = vc_dispmanx_update_submit( update, 0, NULL );
if (ret != DISPMANX_SUCCESS ) {
return SDL_SetError("vc_dispmanx_update_submit() failed");
}
}
}
update = vc_dispmanx_update_start(10);
if (!update) {
return 0;
}
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = curdata->w << 16;
src_rect.height = curdata->h << 16;
dst_rect.x = x;
dst_rect.y = y;
dst_rect.width = curdata->w;
dst_rect.height = curdata->h;
ret = vc_dispmanx_element_change_attributes(
update,
curdata->element,
0,
0,
0,
&dst_rect,
&src_rect,
DISPMANX_NO_HANDLE,
DISPMANX_NO_ROTATE);
if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
}
/* Submit asynchronously, otherwise the peformance suffers a lot */
ret = vc_dispmanx_update_submit(update, 0, NULL);
if (ret != DISPMANX_SUCCESS) {
return SDL_SetError("vc_dispmanx_update_submit() failed");
}
return 0;
}