mirror of
				https://github.com/Ryujinx/SDL.git
				synced 2025-11-04 15:34:58 +00:00 
			
		
		
		
	Fixed crash if GetRectDisplayIndex() is called before SDL_VideoInit()
This commit is contained in:
		
							parent
							
								
									6926d046c0
								
							
						
					
					
						commit
						d87048fd5a
					
				| 
						 | 
				
			
			@ -1122,25 +1122,27 @@ static int GetRectDisplayIndex(int x, int y, int w, int h)
 | 
			
		|||
    center.x = x + w / 2;
 | 
			
		||||
    center.y = y + h / 2;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < _this->num_displays; ++i) {
 | 
			
		||||
        SDL_Rect display_rect;
 | 
			
		||||
        SDL_GetDisplayBounds(i, &display_rect);
 | 
			
		||||
    if (_this) {
 | 
			
		||||
        for (i = 0; i < _this->num_displays; ++i) {
 | 
			
		||||
            SDL_Rect display_rect;
 | 
			
		||||
            SDL_GetDisplayBounds(i, &display_rect);
 | 
			
		||||
 | 
			
		||||
        /* Check if the window is fully enclosed */
 | 
			
		||||
        if (SDL_EnclosePoints(¢er, 1, &display_rect, NULL)) {
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
            /* Check if the window is fully enclosed */
 | 
			
		||||
            if (SDL_EnclosePoints(¢er, 1, &display_rect, NULL)) {
 | 
			
		||||
                return i;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        /* Snap window center to the display rect */
 | 
			
		||||
        closest_point_on_display = center;
 | 
			
		||||
        SDL_GetClosestPointOnRect(&display_rect, &closest_point_on_display);
 | 
			
		||||
            /* Snap window center to the display rect */
 | 
			
		||||
            closest_point_on_display = center;
 | 
			
		||||
            SDL_GetClosestPointOnRect(&display_rect, &closest_point_on_display);
 | 
			
		||||
 | 
			
		||||
        delta.x = center.x - closest_point_on_display.x;
 | 
			
		||||
        delta.y = center.y - closest_point_on_display.y;
 | 
			
		||||
        dist = (delta.x * delta.x + delta.y * delta.y);
 | 
			
		||||
        if (dist < closest_dist) {
 | 
			
		||||
            closest = i;
 | 
			
		||||
            closest_dist = dist;
 | 
			
		||||
            delta.x = center.x - closest_point_on_display.x;
 | 
			
		||||
            delta.y = center.y - closest_point_on_display.y;
 | 
			
		||||
            dist = (delta.x * delta.x + delta.y * delta.y);
 | 
			
		||||
            if (dist < closest_dist) {
 | 
			
		||||
                closest = i;
 | 
			
		||||
                closest_dist = dist;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue