git repos / blockattack-game

blame: source/code/sago/SagoMiscSdl2.cpp

normal view · raw

4e257de2 sago007 2016-01-22 17:43 1
/*
4e257de2 sago007 2016-01-22 17:43 2
  Copyright (c) 2016 Poul Sander
4e257de2 sago007 2016-01-22 17:43 3
4e257de2 sago007 2016-01-22 17:43 4
  Permission is hereby granted, free of charge, to any person
4e257de2 sago007 2016-01-22 17:43 5
  obtaining a copy of this software and associated documentation files
4e257de2 sago007 2016-01-22 17:43 6
  (the "Software"), to deal in the Software without restriction,
4e257de2 sago007 2016-01-22 17:43 7
  including without limitation the rights to use, copy, modify, merge,
4e257de2 sago007 2016-01-22 17:43 8
  publish, distribute, sublicense, and/or sell copies of the Software,
4e257de2 sago007 2016-01-22 17:43 9
  and to permit persons to whom the Software is furnished to do so,
4e257de2 sago007 2016-01-22 17:43 10
  subject to the following conditions:
4e257de2 sago007 2016-01-22 17:43 11
4e257de2 sago007 2016-01-22 17:43 12
  The above copyright notice and this permission notice shall be
4e257de2 sago007 2016-01-22 17:43 13
  included in all copies or substantial portions of the Software.
4e257de2 sago007 2016-01-22 17:43 14
4e257de2 sago007 2016-01-22 17:43 15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4e257de2 sago007 2016-01-22 17:43 16
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4e257de2 sago007 2016-01-22 17:43 17
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
4e257de2 sago007 2016-01-22 17:43 18
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
4e257de2 sago007 2016-01-22 17:43 19
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
4e257de2 sago007 2016-01-22 17:43 20
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4e257de2 sago007 2016-01-22 17:43 21
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4e257de2 sago007 2016-01-22 17:43 22
  SOFTWARE.
4e257de2 sago007 2016-01-22 17:43 23
*/
4e257de2 sago007 2016-01-22 17:43 24
4e257de2 sago007 2016-01-22 17:43 25
#include "SagoMiscSdl2.hpp"
4e257de2 sago007 2016-01-22 17:43 26
#include "SDL.h"
4e257de2 sago007 2016-01-22 17:43 27
4e257de2 sago007 2016-01-22 17:43 28
void sago::SagoFatalError(const char* errorMsg) {
4e257de2 sago007 2016-01-22 17:43 29
	const SDL_MessageBoxButtonData buttons[] = {
4e257de2 sago007 2016-01-22 17:43 30
        { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Ok" },
4e257de2 sago007 2016-01-22 17:43 31
    };
4e257de2 sago007 2016-01-22 17:43 32
	const SDL_MessageBoxData messageboxdata = {
4e257de2 sago007 2016-01-22 17:43 33
        SDL_MESSAGEBOX_INFORMATION, /* .flags */
4e257de2 sago007 2016-01-22 17:43 34
        nullptr, /* .window */
4e257de2 sago007 2016-01-22 17:43 35
        "Fatal error", /* .title */
4e257de2 sago007 2016-01-22 17:43 36
        errorMsg, /* .message */
4e257de2 sago007 2016-01-22 17:43 37
        SDL_arraysize(buttons), /* .numbuttons */
4e257de2 sago007 2016-01-22 17:43 38
        buttons, /* .buttons */
4e257de2 sago007 2016-01-22 17:43 39
        nullptr /* .colorScheme */
4e257de2 sago007 2016-01-22 17:43 40
    };
4e257de2 sago007 2016-01-22 17:43 41
	int buttonid;
4e257de2 sago007 2016-01-22 17:43 42
    SDL_ShowMessageBox(&messageboxdata, &buttonid);
4e257de2 sago007 2016-01-22 17:43 43
	abort();
4e257de2 sago007 2016-01-22 17:43 44
}
4e257de2 sago007 2016-01-22 17:43 45
c3fc09e9 sago007 2016-01-22 18:31 46
void sago::SagoFatalErrorF(const char* fmt, ...) {
c3fc09e9 sago007 2016-01-22 18:31 47
	char buffer[1024];
c3fc09e9 sago007 2016-01-22 18:31 48
	va_list args;
c3fc09e9 sago007 2016-01-22 18:31 49
	va_start(args, fmt);
c3fc09e9 sago007 2016-01-22 18:31 50
	vsnprintf(buffer, sizeof(buffer), fmt, args);
c3fc09e9 sago007 2016-01-22 18:31 51
	SagoFatalError(buffer);
c3fc09e9 sago007 2016-01-22 18:31 52
	va_end(args);
c3b697c6 sago007 2016-02-07 17:30 53
}
c3b697c6 sago007 2016-02-07 17:30 54
1970-01-01 00:00 55