Changeset - r9470:75edf93b1c69
[Not reviewed]
master
0 19 0
glx - 16 years ago 2008-06-05 20:54:52
glx@openttd.org
(svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
19 files changed with 67 insertions and 46 deletions:
0 comments (0 inline, 0 general)
src/driver.cpp
Show inline comments
 
@@ -84,13 +84,13 @@ const Driver *DriverFactoryBase::SelectD
 
				}
 

	
 
				DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
 
				delete newd;
 
			}
 
		}
 
		error("Couldn't find any suitable %s driver", GetDriverTypeName(type));
 
		usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type));
 
	} else {
 
		char *parm;
 
		char buffer[256];
 
		const char *parms[32];
 

	
 
		/* Extract the driver name and put parameter list in parm */
 
@@ -122,21 +122,21 @@ const Driver *DriverFactoryBase::SelectD
 
			/* Found our driver, let's try it */
 
			Driver *newd = d->CreateInstance();
 

	
 
			const char *err = newd->Start(parms);
 
			if (err != NULL) {
 
				delete newd;
 
				error("Unable to load driver '%s'. The error was: %s", d->name, err);
 
				usererror("Unable to load driver '%s'. The error was: %s", d->name, err);
 
			}
 

	
 
			DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
 
			delete *GetActiveDriver(type);
 
			*GetActiveDriver(type) = newd;
 
			return newd;
 
		}
 
		error("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
 
		usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
 
	}
 
}
 

	
 
/**
 
 * Register a driver internally, based on its name.
 
 * @param name the name of the driver.
src/fileio.cpp
Show inline comments
 
@@ -183,13 +183,13 @@ void FioOpenFile(int slot, const char *f
 
	FILE *f;
 

	
 
#if defined(LIMITED_FDS)
 
	FioFreeHandle();
 
#endif /* LIMITED_FDS */
 
	f = FioFOpenFile(filename);
 
	if (f == NULL) error("Cannot open file '%s'", filename);
 
	if (f == NULL) usererror("Cannot open file '%s'", filename);
 
	uint32 pos = ftell(f);
 

	
 
	FioCloseFile(slot); // if file was opened before, close it
 
	_fio.handles[slot] = f;
 
	_fio.filenames[slot] = filename;
 

	
src/gfxinit.cpp
Show inline comments
 
@@ -52,13 +52,13 @@ static uint LoadGrfFile(const char *file
 
	DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
 

	
 
	while (LoadNextSprite(load_index, file_index, sprite_id)) {
 
		load_index++;
 
		sprite_id++;
 
		if (load_index >= MAX_SPRITES) {
 
			error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
 
			usererror("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
 
		}
 
	}
 
	DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
 

	
 
	return load_index - load_index_org;
 
}
src/network/network_server.cpp
Show inline comments
 
@@ -320,18 +320,18 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 

	
 
	if (cs->status == STATUS_AUTH) {
 
		const char *filename = "network_server.tmp";
 
		Packet *p;
 

	
 
		// Make a dump of the current game
 
		if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) error("network savedump failed");
 
		if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) usererror("network savedump failed");
 

	
 
		file_pointer = FioFOpenFile(filename, "rb", AUTOSAVE_DIR);
 
		fseek(file_pointer, 0, SEEK_END);
 

	
 
		if (ftell(file_pointer) == 0) error("network savedump failed - zero sized savegame?");
 
		if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?");
 

	
 
		// Now send the _frame_counter and how many packets are coming
 
		p = NetworkSend_Init(PACKET_SERVER_MAP);
 
		p->Send_uint8 (MAP_PACKET_START);
 
		p->Send_uint32(_frame_counter);
 
		p->Send_uint32(ftell(file_pointer));
 
@@ -352,13 +352,13 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 
		int res;
 
		for (i = 0; i < sent_packets; i++) {
 
			Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
 
			p->Send_uint8(MAP_PACKET_NORMAL);
 
			res = (int)fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer);
 

	
 
			if (ferror(file_pointer)) error("Error reading temporary network savegame!");
 
			if (ferror(file_pointer)) usererror("Error reading temporary network savegame!");
 

	
 
			p->size += res;
 
			cs->Send_Packet(p);
 
			if (feof(file_pointer)) {
 
				// Done reading!
 
				Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
src/newgrf.cpp
Show inline comments
 
@@ -5780,13 +5780,13 @@ void LoadNewGRFFile(GRFConfig *config, u
 
	 *
 
	 * During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9, 0A and 0B are
 
	 * carried out.  All others are ignored, because they only need to be
 
	 * processed once at initialization.  */
 
	if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
 
		_cur_grffile = GetFileByFilename(filename);
 
		if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
 
		if (_cur_grffile == NULL) usererror("File '%s' lost in cache.\n", filename);
 
		if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
 
		if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
 
		_cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF();
 
	}
 

	
 
	if (file_index > LAST_GRF_SLOT) {
 
@@ -5986,13 +5986,13 @@ void LoadNewGRF(uint load_index, uint fi
 
		_cur_stage = stage;
 
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
 
			if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
 

	
 
			/* @todo usererror() */
 
			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
 
			if (!FioCheckFileExists(c->filename)) usererror("NewGRF file is missing '%s'", c->filename);
 

	
 
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
 
			LoadNewGRFFile(c, slot++, stage);
 
			if (stage == GLS_RESERVE) {
 
				SetBit(c->flags, GCF_RESERVED);
 
			} else if (stage == GLS_ACTIVATION) {
src/openttd.cpp
Show inline comments
 
@@ -96,30 +96,50 @@ void ResetMusic();
 
void ResetOldNames();
 
void ProcessAsyncSaveFinish();
 
void CallWindowTickEvent();
 

	
 
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
 
extern Player* DoStartupNewPlayer(bool is_ai);
 
extern void ShowOSErrorBox(const char *buf);
 
extern void ShowOSErrorBox(const char *buf, bool system);
 
extern void InitializeRailGUI();
 

	
 
/**
 
 * Error handling for fatal errors.
 
 * Error handling for fatal user errors.
 
 * @param s the string to print.
 
 * @note Does NEVER return.
 
 */
 
void CDECL usererror(const char *s, ...)
 
{
 
	va_list va;
 
	char buf[512];
 

	
 
	va_start(va, s);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 

	
 
	ShowOSErrorBox(buf, false);
 
	if (_video_driver != NULL) _video_driver->Stop();
 

	
 
	exit(1);
 
}
 

	
 
/**
 
 * Error handling for fatal non-user errors.
 
 * @param s the string to print.
 
 * @note Does NEVER return.
 
 */
 
void CDECL error(const char *s, ...)
 
{
 
	va_list va;
 
	char buf[512];
 

	
 
	va_start(va, s);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 

	
 
	ShowOSErrorBox(buf);
 
	ShowOSErrorBox(buf, true);
 
	if (_video_driver != NULL) _video_driver->Stop();
 

	
 
	assert(0);
 
	exit(1);
 
}
 

	
 
@@ -521,36 +541,36 @@ int ttd_main(int argc, char *argv[])
 
	/* Initialize game palette */
 
	GfxInitPalettes();
 

	
 
	DEBUG(misc, 1, "Loading blitter...");
 
	if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL)
 
		StrEmpty(_ini_blitter) ?
 
			error("Failed to autoprobe blitter") :
 
			error("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
 
			usererror("Failed to autoprobe blitter") :
 
			usererror("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
 

	
 
	DEBUG(driver, 1, "Loading drivers...");
 

	
 
	_sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND);
 
	if (_sound_driver == NULL) {
 
		StrEmpty(_ini_sounddriver) ?
 
			error("Failed to autoprobe sound driver") :
 
			error("Failed to select requested sound driver '%s'", _ini_sounddriver);
 
			usererror("Failed to autoprobe sound driver") :
 
			usererror("Failed to select requested sound driver '%s'", _ini_sounddriver);
 
	}
 

	
 
	_music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC);
 
	if (_music_driver == NULL) {
 
		StrEmpty(_ini_musicdriver) ?
 
			error("Failed to autoprobe music driver") :
 
			error("Failed to select requested music driver '%s'", _ini_musicdriver);
 
			usererror("Failed to autoprobe music driver") :
 
			usererror("Failed to select requested music driver '%s'", _ini_musicdriver);
 
	}
 

	
 
	_video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO);
 
	if (_video_driver == NULL) {
 
		StrEmpty(_ini_videodriver) ?
 
			error("Failed to autoprobe video driver") :
 
			error("Failed to select requested video driver '%s'", _ini_videodriver);
 
			usererror("Failed to autoprobe video driver") :
 
			usererror("Failed to select requested video driver '%s'", _ini_videodriver);
 
	}
 

	
 
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
 
	/* Initialize the zoom level of the screen to normal */
 
	_screen.zoom = ZOOM_LVL_NORMAL;
 

	
src/os2.cpp
Show inline comments
 
@@ -142,13 +142,13 @@ void ShowInfo(const char *str)
 

	
 
	// terminate PM env.
 
	WinDestroyMsgQueue(hmq);
 
	WinTerminate(hab);
 
}
 

	
 
void ShowOSErrorBox(const char *buf)
 
void ShowOSErrorBox(const char *buf, bool system)
 
{
 
	HAB hab;
 
	HMQ hmq;
 
	ULONG rc;
 

	
 
	// init PM env.
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1465,13 +1465,13 @@ static bool IndividualRoadVehicleControl
 
			dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3));
 
		} else {
 
			dir = FollowPreviousRoadVehicle(v, prev, tile, (DiagDirection)(rd.x & 3), false);
 
		}
 

	
 
		if (dir == INVALID_TRACKDIR) {
 
			if (!IsRoadVehFront(v)) error("!Disconnecting road vehicle.");
 
			if (!IsRoadVehFront(v)) error("Disconnecting road vehicle.");
 
			v->cur_speed = 0;
 
			return false;
 
		}
 

	
 
again:
 
		uint start_frame = RVC_DEFAULT_START_FRAME;
src/sound/win32_s.cpp
Show inline comments
 
@@ -21,24 +21,24 @@ static void PrepareHeader(WAVEHDR *hdr)
 
{
 
	hdr->dwBufferLength = _bufsize * 4;
 
	hdr->dwFlags = 0;
 
	hdr->lpData = MallocT<char>(_bufsize * 4);
 
	if (hdr->lpData == NULL ||
 
			waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
 
		error("waveOutPrepareHeader failed");
 
		usererror("waveOutPrepareHeader failed");
 
}
 

	
 
static void FillHeaders()
 
{
 
	WAVEHDR *hdr;
 

	
 
	for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) {
 
		if (!(hdr->dwFlags & WHDR_INQUEUE)) {
 
			MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4);
 
			if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
 
				error("waveOutWrite failed");
 
				usererror("waveOutWrite failed");
 
		}
 
	}
 
}
 

	
 
static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
 
	DWORD dwParam1, DWORD dwParam2)
src/spritecache.cpp
Show inline comments
 
@@ -166,13 +166,13 @@ static void* ReadSprite(SpriteCache *sc,
 
	/* Type 0xFF indicates either a colormap or some other non-sprite info */
 
	if (type == 0xFF) {
 
		if (real_sprite) {
 
			static byte warning_level = 0;
 
			DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id);
 
			warning_level = 6;
 
			if (id == SPR_IMG_QUERY) error("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?");
 
			if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?");
 
			return (void*)GetSprite(SPR_IMG_QUERY);
 
		}
 

	
 
		byte *dest = (byte *)AllocSprite(num);
 

	
 
		sc->ptr = dest;
 
@@ -243,13 +243,13 @@ bool LoadNextSprite(int load_index, byte
 
	SpriteCache *sc;
 
	size_t file_pos = FioGetPos();
 

	
 
	if (!ReadSpriteHeaderSkipData()) return false;
 

	
 
	if (load_index >= MAX_SPRITES) {
 
		error("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
 
		usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
 
	}
 

	
 
	sc = AllocateSpriteCache(load_index);
 
	sc->file_slot = file_slot;
 
	sc->file_pos = file_pos;
 
	sc->ptr = NULL;
src/stdafx.h
Show inline comments
 
@@ -314,12 +314,13 @@ assert_compile(sizeof(uint8)  == 1);
 
#if defined(__APPLE__)
 
	#define GetString OTTD_GetString
 
	#define DrawString OTTD_DrawString
 
	#define CloseConnection OTTD_CloseConnection
 
#endif /* __APPLE__ */
 

	
 
void NORETURN CDECL usererror(const char *str, ...);
 
void NORETURN CDECL error(const char *str, ...);
 
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
 

	
 
#if defined(MORPHOS) || defined(__NDS__)
 
	/* MorphOS and NDS don't have C++ conformant _stricmp... */
 
	#define _stricmp stricmp
src/strings.cpp
Show inline comments
 
@@ -175,13 +175,13 @@ static char *GetStringWithArgs(char *buf
 

	
 
			return FormatString(buffr, _userstring, NULL, 0, last);
 
	}
 

	
 
	if (index >= _langtab_num[tab]) {
 
		error(
 
			"!String 0x%X is invalid. "
 
			"String 0x%X is invalid. "
 
			"Probably because an old version of the .lng file.\n", string
 
		);
 
	}
 

	
 
	return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8), last);
 
}
 
@@ -1424,13 +1424,13 @@ void InitializeLanguagePacks()
 

	
 
	FOR_ALL_SEARCHPATHS(sp) {
 
		char path[MAX_PATH];
 
		FioAppendDirectory(path, lengthof(path), sp, LANG_DIR);
 
		language_count += GetLanguageList(files, language_count, lengthof(files), path);
 
	}
 
	if (language_count == 0) error("No available language packs (invalid versions?)");
 
	if (language_count == 0) usererror("No available language packs (invalid versions?)");
 

	
 
	/* Acquire the locale of the current system */
 
	const char *lang = GetCurrentLocale("LC_MESSAGES");
 
	if (lang == NULL) lang = "en_GB";
 

	
 
	int chosen_language   = -1; ///< Matching the language in the configuartion file or the current locale
 
@@ -1460,21 +1460,21 @@ void InitializeLanguagePacks()
 
			if (strncmp(hdr.isocode, lang, 2) == 0) language_fallback = dl->num;
 
		}
 

	
 
		dl->num++;
 
	}
 

	
 
	if (dl->num == 0) error("Invalid version of language packs");
 
	if (dl->num == 0) usererror("Invalid version of language packs");
 

	
 
	/* We haven't found the language in the config nor the one in the locale.
 
	 * Now we set it to one of the fallback languages */
 
	if (chosen_language == -1) {
 
		chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback;
 
	}
 

	
 
	if (!ReadLanguagePack(chosen_language)) error("Can't read language pack '%s'", dl->ent[chosen_language].file);
 
	if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", dl->ent[chosen_language].file);
 
}
 

	
 
/**
 
 * Check whether the currently loaded language pack
 
 * uses characters that the currently loaded font
 
 * does not support. If this is the case an error
src/town_cmd.cpp
Show inline comments
 
@@ -1600,13 +1600,13 @@ bool GenerateTowns()
 
	} while (--n);
 

	
 
	/* give it a last try, but now more aggressive */
 
	if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
 
		if (GetNumTowns() == 0) {
 
			/* XXX - can we handle that more gracefully? */
 
			if (_game_mode != GM_EDITOR) error("Could not generate any town");
 
			if (_game_mode != GM_EDITOR) usererror("Could not generate any town");
 

	
 
			return false;
 
		}
 
	}
 

	
 
	return true;
src/train_cmd.cpp
Show inline comments
 
@@ -3110,13 +3110,13 @@ static void TrainController(Vehicle *v, 
 
		}
 
	}
 
	return;
 

	
 
invalid_rail:
 
	/* We've reached end of line?? */
 
	if (prev != NULL) error("!Disconnecting train");
 
	if (prev != NULL) error("Disconnecting train");
 

	
 
reverse_train_direction:
 
	v->load_unload_time_rem = 0;
 
	v->cur_speed = 0;
 
	v->subspeed = 0;
 
	ReverseTrainDirection(v);
src/unix.cpp
Show inline comments
 
@@ -211,13 +211,13 @@ const char *OTTD2FS(const char *name) {r
 

	
 
void ShowInfo(const char *str)
 
{
 
	fprintf(stderr, "%s\n", str);
 
}
 

	
 
void ShowOSErrorBox(const char *buf)
 
void ShowOSErrorBox(const char *buf, bool system)
 
{
 
#if defined(__APPLE__)
 
	/* this creates an NSAlertPanel with the contents of 'buf'
 
	 * this is the native and nicest way to do this on OSX */
 
	ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" );
 
#else
src/video/dedicated_v.cpp
Show inline comments
 
@@ -104,16 +104,16 @@ static void WINAPI CheckForConsoleInput(
 
static void CreateWindowsConsoleThread()
 
{
 
	DWORD dwThreadId;
 
	/* Create event to signal when console input is ready */
 
	_hInputReady = CreateEvent(NULL, false, false, NULL);
 
	_hWaitForInputHandling = CreateEvent(NULL, false, false, NULL);
 
	if (_hInputReady == NULL || _hWaitForInputHandling == NULL) error("Cannot create console event!");
 
	if (_hInputReady == NULL || _hWaitForInputHandling == NULL) usererror("Cannot create console event!");
 

	
 
	_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
 
	if (_hThread == NULL) error("Cannot create console thread!");
 
	if (_hThread == NULL) usererror("Cannot create console thread!");
 

	
 
	DEBUG(driver, 2, "Windows console thread started");
 
}
 

	
 
static void CloseWindowsConsoleThread()
 
{
src/video/sdl_v.cpp
Show inline comments
 
@@ -115,13 +115,13 @@ static void GetVideoModes()
 
	int i;
 
	SDL_Rect **modes;
 

	
 
	modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0));
 

	
 
	if (modes == NULL)
 
		error("sdl: no modes available");
 
		usererror("sdl: no modes available");
 

	
 
	_all_modes = (modes == (void*)-1);
 

	
 
	if (_all_modes) {
 
		// all modes available, put some default ones here
 
		memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
 
@@ -195,13 +195,13 @@ static bool CreateMainSurface(int w, int
 
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	GetAvailableVideoMode(&w, &h);
 

	
 
	DEBUG(driver, 1, "SDL: using mode %dx%dx%d", w, h, bpp);
 

	
 
	if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
 
	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
 

	
 
	/* Give the application an icon */
 
	icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp");
 
	if (icon != NULL) {
 
		/* Get the colourkey, which will be magenta */
 
		uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255);
src/video/win32_v.cpp
Show inline comments
 
@@ -56,13 +56,13 @@ static void MakePalette()
 
		pal->palPalEntry[i].peGreen = _cur_palette[i].g;
 
		pal->palPalEntry[i].peBlue  = _cur_palette[i].b;
 
		pal->palPalEntry[i].peFlags = 0;
 

	
 
	}
 
	_wnd.gdi_palette = CreatePalette(pal);
 
	if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n");
 
	if (_wnd.gdi_palette == NULL) usererror("CreatePalette failed!\n");
 
}
 

	
 
static void UpdatePalette(HDC dc, uint start, uint count)
 
{
 
	RGBQUAD rgb[256];
 
	uint i;
 
@@ -289,13 +289,13 @@ static bool MakeWindow(bool full_screen)
 
		} else {
 
			TCHAR Windowtitle[50];
 

	
 
			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
 

	
 
			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
 
			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
 
			if (_wnd.main_wnd == NULL) usererror("CreateWindow failed");
 
			ShowWindow(_wnd.main_wnd, showstyle);
 
		}
 
	}
 
	GameSizeChanged(); // invalidate all windows, force redraw
 
	return true; // the request succedded
 
}
 
@@ -668,26 +668,26 @@ static void RegisterWndClass()
 
			0,
 
			0,
 
			_T("OTTD")
 
		};
 

	
 
		registered = true;
 
		if (!RegisterClass(&wnd)) error("RegisterClass failed");
 
		if (!RegisterClass(&wnd)) usererror("RegisterClass failed");
 
	}
 
}
 

	
 
static bool AllocateDibSection(int w, int h)
 
{
 
	BITMAPINFO *bi;
 
	HDC dc;
 
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	w = max(w, 64);
 
	h = max(h, 64);
 

	
 
	if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
 
	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
 

	
 
	if (w == _screen.width && h == _screen.height)
 
		return false;
 

	
 
	_screen.width = w;
 
	_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
 
@@ -704,13 +704,13 @@ static bool AllocateDibSection(int w, in
 
	bi->bmiHeader.biCompression = BI_RGB;
 

	
 
	if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
 

	
 
	dc = GetDC(0);
 
	_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
 
	if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
 
	if (_wnd.dib_sect == NULL) usererror("CreateDIBSection failed");
 
	ReleaseDC(0, dc);
 

	
 
	return true;
 
}
 

	
 
static const uint16 default_resolutions[][2] = {
src/win32.cpp
Show inline comments
 
@@ -89,20 +89,20 @@ void SetExceptionString(const char *s, .
 
	va_end(va);
 

	
 
	_exception_string = strdup(buf);
 
}
 
#endif
 

	
 
void ShowOSErrorBox(const char *buf)
 
void ShowOSErrorBox(const char *buf, bool system)
 
{
 
	MyShowCursor(true);
 
	MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP);
 

	
 
/* if exception tracker is enabled, we crash here to let the exception handler handle it. */
 
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG)
 
	if (*buf == '!') {
 
	if (system) {
 
		_exception_string = buf;
 
		*(byte*)0 = 0;
 
	}
 
#endif
 
}
 

	
 
@@ -958,13 +958,13 @@ int APIENTRY WinMain(HINSTANCE hInstance
 
#endif /* UNICODE */
 

	
 
#if defined(UNICODE)
 

	
 
#if !defined(WINCE)
 
	/* Check if a win9x user started the win32 version */
 
	if (HasBit(GetVersion(), 31)) error("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again.");
 
	if (HasBit(GetVersion(), 31)) usererror("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again.");
 
#endif
 

	
 
	/* For UNICODE we need to convert the commandline to char* _AND_
 
	 * save it because argv[] points into this buffer and thus needs to
 
	 * be available between subsequent calls to FS2OTTD() */
 
	char cmdlinebuf[MAX_PATH];
0 comments (0 inline, 0 general)