visualtest/unittest/testquit.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 29 May 2020 21:26:32 -0700
changeset 13884 ba1ed72249c0
parent 12758 3c6a6dad3487
permissions -rw-r--r--
Fixed bug 5113 - SDL_UpdateWindowSurfaceRects BitBlt the entire surface on Win32

Ryan C. Gordon

As discussed here:
https://discourse.libsdl.org/t/question-about-implementation-of-sdl-updatewindowsurfacerects/27561

"As you can see this function [WIN_UpdateWindowFramebuffer, in src/video/windows/SDL_windowsframebuffer.c] calls BitBlt on entire screen, even though it accepts the rects. Rects variable is not even used in this function at all. Now my question is why is that the case?"
     1 /*
     2   Copyright (C) 2013 Apoorv Upreti <apoorvupreti@gmail.com>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 /* Quits, hangs or crashes based on the command line options passed. */
    13 
    14 #include <SDL.h>
    15 #include <SDL_test.h>
    16 
    17 static SDLTest_CommonState *state;
    18 static int exit_code;
    19 static SDL_bool hang;
    20 static SDL_bool crash;
    21 
    22 int
    23 main(int argc, char** argv)
    24 {
    25     int i, done;
    26     SDL_Event event;
    27 
    28     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    29     if(!state)
    30         return 1;
    31 
    32     state->window_flags |= SDL_WINDOW_RESIZABLE;
    33     
    34     exit_code = 0;
    35     hang = SDL_FALSE;
    36     crash = SDL_FALSE;
    37 
    38     for(i = 1; i < argc; )
    39     {
    40         int consumed;
    41         consumed = SDLTest_CommonArg(state, i);
    42         if(consumed == 0)
    43         {
    44             consumed = -1;
    45             if(SDL_strcasecmp(argv[i], "--exit-code") == 0)
    46             {
    47                 if(argv[i + 1])
    48                 {
    49                     exit_code = SDL_atoi(argv[i + 1]);
    50                     consumed = 2;
    51                 }
    52             }
    53             else if(SDL_strcasecmp(argv[i], "--hang") == 0)
    54             {
    55                 hang = SDL_TRUE;
    56                 consumed = 1;
    57             }
    58             else if(SDL_strcasecmp(argv[i], "--crash") == 0)
    59             {
    60                 crash = SDL_TRUE;
    61                 consumed = 1;
    62             }
    63         }
    64 
    65         if(consumed < 0)
    66         {
    67             static const char *options = { "[--exit-code N]", "[--crash]", "[--hang]", NULL };
    68             SDLTest_CommonLogUsage(state, argv[0], options);
    69             SDLTest_CommonQuit(state);
    70             return 1;
    71         }
    72         i += consumed;
    73     }
    74 
    75     if(!SDLTest_CommonInit(state))
    76     {
    77         SDLTest_CommonQuit(state);
    78         return 1;
    79     }
    80 
    81     /* infinite loop to hang the process */
    82     while(hang)
    83         SDL_Delay(10);
    84 
    85     /* dereference NULL pointer to crash process */
    86     if(crash)
    87     {
    88         int* p = NULL;
    89         *p = 5;
    90     }
    91 
    92     /* event loop */
    93     done = 0;
    94     while(!done)
    95     {
    96         while(SDL_PollEvent(&event))
    97             SDLTest_CommonEvent(state, &event, &done);
    98         SDL_Delay(10);
    99     }
   100 
   101     return exit_code;
   102 }