Fixed bug 3451 - Raspberry Pi Raspbian SDL_assert triggered sometimes at RPI_WarpMouseGlobal
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Oct 2016 04:53:01 -0700
changeset 105299e549b5e0f44
parent 10528 0b9e7c421d36
child 10530 2a3f8bc23daa
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.
src/video/raspberry/SDL_rpimouse.c
     1.1 --- a/src/video/raspberry/SDL_rpimouse.c	Thu Oct 13 04:01:25 2016 -0700
     1.2 +++ b/src/video/raspberry/SDL_rpimouse.c	Thu Oct 13 04:53:01 2016 -0700
     1.3 @@ -87,17 +87,17 @@
     1.4      curdata->h = surface->h;
     1.5      
     1.6      /* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */
     1.7 -    curdata->resource = vc_dispmanx_resource_create( VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy );
     1.8 +    curdata->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy);
     1.9      SDL_assert(curdata->resource);
    1.10 -    vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h);
    1.11 +    vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
    1.12      /* A note from Weston: 
    1.13       * vc_dispmanx_resource_write_data() ignores ifmt,
    1.14       * rect.x, rect.width, and uses stride only for computing
    1.15       * the size of the transfer as rect.height * stride.
    1.16       * Therefore we can only write rows starting at x=0.
    1.17       */
    1.18 -    ret = vc_dispmanx_resource_write_data( curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect );
    1.19 -    SDL_assert ( ret == DISPMANX_SUCCESS );
    1.20 +    ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect);
    1.21 +    SDL_assert (ret == DISPMANX_SUCCESS);
    1.22      
    1.23      cursor->driverdata = curdata;
    1.24      
    1.25 @@ -126,15 +126,15 @@
    1.26      if (cursor == NULL) {
    1.27          /* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */
    1.28  
    1.29 -        if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
    1.30 +        if (mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
    1.31              curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
    1.32              if (curdata->element > DISPMANX_NO_HANDLE) {
    1.33 -                update = vc_dispmanx_update_start( 10 );
    1.34 -                SDL_assert( update );
    1.35 -                ret = vc_dispmanx_element_remove( update, curdata->element );
    1.36 -                SDL_assert( ret == DISPMANX_SUCCESS );
    1.37 -                ret = vc_dispmanx_update_submit_sync( update );
    1.38 -                SDL_assert( ret == DISPMANX_SUCCESS );
    1.39 +                update = vc_dispmanx_update_start(10);
    1.40 +                SDL_assert(update);
    1.41 +                ret = vc_dispmanx_element_remove(update, curdata->element);
    1.42 +                SDL_assert(ret == DISPMANX_SUCCESS);
    1.43 +                ret = vc_dispmanx_update_submit_sync(update);
    1.44 +                SDL_assert(ret == DISPMANX_SUCCESS);
    1.45                  curdata->element = DISPMANX_NO_HANDLE;
    1.46              }
    1.47          }
    1.48 @@ -161,13 +161,13 @@
    1.49      }
    1.50      
    1.51      if (curdata->element == DISPMANX_NO_HANDLE) {
    1.52 -        vc_dispmanx_rect_set( &src_rect, 0, 0, curdata->w << 16, curdata->h << 16 );
    1.53 -        vc_dispmanx_rect_set( &dst_rect, 0, 0, curdata->w, curdata->h);
    1.54 +        vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
    1.55 +        vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
    1.56          
    1.57 -        update = vc_dispmanx_update_start( 10 );
    1.58 -        SDL_assert( update );
    1.59 +        update = vc_dispmanx_update_start(10);
    1.60 +        SDL_assert(update);
    1.61  
    1.62 -        curdata->element = vc_dispmanx_element_add( update,
    1.63 +        curdata->element = vc_dispmanx_element_add(update,
    1.64                                                      data->dispman_display,
    1.65                                                      SDL_RPI_MOUSELAYER, // layer
    1.66                                                      &dst_rect,
    1.67 @@ -176,10 +176,10 @@
    1.68                                                      DISPMANX_PROTECTION_NONE,
    1.69                                                      &alpha,
    1.70                                                      DISPMANX_NO_HANDLE, // clamp
    1.71 -                                                    VC_IMAGE_ROT0 );
    1.72 -        SDL_assert( curdata->element > DISPMANX_NO_HANDLE);
    1.73 -        ret = vc_dispmanx_update_submit_sync( update );
    1.74 -        SDL_assert( ret == DISPMANX_SUCCESS );
    1.75 +                                                    VC_IMAGE_ROT0);
    1.76 +        SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
    1.77 +        ret = vc_dispmanx_update_submit_sync(update);
    1.78 +        SDL_assert(ret == DISPMANX_SUCCESS);
    1.79      }
    1.80      
    1.81      return 0;
    1.82 @@ -198,17 +198,17 @@
    1.83          
    1.84          if (curdata != NULL) {
    1.85              if (curdata->element != DISPMANX_NO_HANDLE) {
    1.86 -                update = vc_dispmanx_update_start( 10 );
    1.87 -                SDL_assert( update );
    1.88 -                ret = vc_dispmanx_element_remove( update, curdata->element );
    1.89 -                SDL_assert( ret == DISPMANX_SUCCESS );
    1.90 -                ret = vc_dispmanx_update_submit_sync( update );
    1.91 -                SDL_assert( ret == DISPMANX_SUCCESS );
    1.92 +                update = vc_dispmanx_update_start(10);
    1.93 +                SDL_assert(update);
    1.94 +                ret = vc_dispmanx_element_remove(update, curdata->element);
    1.95 +                SDL_assert(ret == DISPMANX_SUCCESS);
    1.96 +                ret = vc_dispmanx_update_submit_sync(update);
    1.97 +                SDL_assert(ret == DISPMANX_SUCCESS);
    1.98              }
    1.99              
   1.100              if (curdata->resource != DISPMANX_NO_HANDLE) {
   1.101 -                ret = vc_dispmanx_resource_delete( curdata->resource );
   1.102 -                SDL_assert( ret == DISPMANX_SUCCESS );
   1.103 +                ret = vc_dispmanx_resource_delete(curdata->resource);
   1.104 +                SDL_assert(ret == DISPMANX_SUCCESS);
   1.105              }
   1.106          
   1.107              SDL_free(cursor->driverdata);
   1.108 @@ -235,41 +235,48 @@
   1.109      VC_RECT_T src_rect;
   1.110      SDL_Mouse *mouse = SDL_GetMouse();
   1.111      
   1.112 -    if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
   1.113 -        curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
   1.114 -        if (curdata->element != DISPMANX_NO_HANDLE) {
   1.115 -            update = vc_dispmanx_update_start( 10 );
   1.116 -            SDL_assert( update );
   1.117 -            src_rect.x = 0;
   1.118 -            src_rect.y = 0;
   1.119 -            src_rect.width  = curdata->w << 16;
   1.120 -            src_rect.height = curdata->h << 16;
   1.121 -            dst_rect.x = x;
   1.122 -            dst_rect.y = y;
   1.123 -            dst_rect.width  = curdata->w;
   1.124 -            dst_rect.height = curdata->h;
   1.125 +    if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
   1.126 +        return 0;
   1.127 +    }
   1.128 +
   1.129 +    curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
   1.130 +    if (curdata->element == DISPMANX_NO_HANDLE) {
   1.131 +        return 0;
   1.132 +    }
   1.133 +
   1.134 +    update = vc_dispmanx_update_start(10);
   1.135 +    if (!update) {
   1.136 +        return 0;
   1.137 +    }
   1.138  
   1.139 -            ret = vc_dispmanx_element_change_attributes(
   1.140 -                update,
   1.141 -                curdata->element,
   1.142 -                0,
   1.143 -                0,
   1.144 -                0,
   1.145 -                &dst_rect,
   1.146 -                &src_rect,
   1.147 -                DISPMANX_NO_HANDLE,
   1.148 -                DISPMANX_NO_ROTATE);
   1.149 -            if (ret != DISPMANX_SUCCESS ) {
   1.150 -                return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
   1.151 -            }
   1.152 +    src_rect.x = 0;
   1.153 +    src_rect.y = 0;
   1.154 +    src_rect.width  = curdata->w << 16;
   1.155 +    src_rect.height = curdata->h << 16;
   1.156 +    dst_rect.x = x;
   1.157 +    dst_rect.y = y;
   1.158 +    dst_rect.width  = curdata->w;
   1.159 +    dst_rect.height = curdata->h;
   1.160  
   1.161 -            /* Submit asynchronously, otherwise the peformance suffers a lot */
   1.162 -            ret = vc_dispmanx_update_submit( update, 0, NULL );
   1.163 -            if (ret != DISPMANX_SUCCESS ) {
   1.164 -                return SDL_SetError("vc_dispmanx_update_submit() failed");
   1.165 -            }
   1.166 -        }
   1.167 -    }   
   1.168 +    ret = vc_dispmanx_element_change_attributes(
   1.169 +        update,
   1.170 +        curdata->element,
   1.171 +        0,
   1.172 +        0,
   1.173 +        0,
   1.174 +        &dst_rect,
   1.175 +        &src_rect,
   1.176 +        DISPMANX_NO_HANDLE,
   1.177 +        DISPMANX_NO_ROTATE);
   1.178 +    if (ret != DISPMANX_SUCCESS) {
   1.179 +        return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
   1.180 +    }
   1.181 +
   1.182 +    /* Submit asynchronously, otherwise the peformance suffers a lot */
   1.183 +    ret = vc_dispmanx_update_submit(update, 0, NULL);
   1.184 +    if (ret != DISPMANX_SUCCESS) {
   1.185 +        return SDL_SetError("vc_dispmanx_update_submit() failed");
   1.186 +    }
   1.187      return 0;
   1.188  }
   1.189