Mercurial > hg > openttd
changeset 3127:c88adf3bfaa6 draft
(svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
It also adds a new error window, which can be used just like assert, but it is also active when asserts are turned off
This is useful for places where it's really important to check even if assert is turned off. It's not used in the code yet
author | bjarni <bjarni@openttd.org> |
---|---|
date | Thu, 02 Mar 2006 21:43:09 +0000 |
parents | 5e106bd1c941 |
children | 809ebf739d3c |
files | os/macosx/macos.h os/macosx/macos.m |
diffstat | 2 files changed, 112 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/os/macosx/macos.h +++ b/os/macosx/macos.h @@ -3,8 +3,17 @@ #ifndef MACOS_H #define MACOS_H +/* + * Functions to show the popup window + * use ShowMacDialog when you want to control title, message and text on the button + * ShowMacAssertDialog is used by assert + * ShowMacErrorDialog should be used when an unrecoverable error shows up. It only contains the title, which will should tell what went wrong + * the function then adds text that tells the user to update and then report the bug if it's present in the newest version + * It also quits in a nice way since we call it when we know something happened that will crash OpenTTD (like a needed pointer turns out to be NULL or similar) + */ void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel ); void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression ); +void ShowMacErrorDialog(const char *error); // Since MacOS X users will never see an assert unless they started the game from a terminal // we're using a custom assert(e) macro.
--- a/os/macosx/macos.m +++ b/os/macosx/macos.m @@ -2,6 +2,20 @@ #include <AppKit/AppKit.h> +#include <mach/mach.h> +#include <mach/mach_host.h> +#include <mach/host_info.h> +#include <mach/machine.h> +#include <stdio.h> +#include "../../stdafx.h" +#include "../../openttd.h" +#include "../../newgrf.h" +#include "../../gfx.h" + +#ifndef CPU_SUBTYPE_POWERPC_970 +#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100) +#endif + /* * This file contains objective C * Apple uses objective C instead of plain C to interact with OS specific/native functions @@ -10,6 +24,82 @@ * To insure that the crosscompiler still works, let him try any changes before they are committed */ +static char *GetOSString(void) +{ + static char buffer[175]; + char CPU[20]; + char OS[20]; + char newgrf[125]; + long sysVersion; + extern const char _openttd_revision[]; + + + // get the hardware info + host_basic_info_data_t hostInfo; + mach_msg_type_number_t infoCount; + + infoCount = HOST_BASIC_INFO_COUNT; + host_info(mach_host_self(), HOST_BASIC_INFO, + (host_info_t)&hostInfo, &infoCount); + + // replace the hardware info with strings, that tells a bit more than just an int +#ifdef __POWERPC__ + switch (hostInfo.cpu_subtype) { + case CPU_SUBTYPE_POWERPC_750: + sprintf(CPU,"G3"); + break; + case CPU_SUBTYPE_POWERPC_7400: + case CPU_SUBTYPE_POWERPC_7450: + sprintf(CPU,"G4"); + break; + case CPU_SUBTYPE_POWERPC_970: + sprintf(CPU,"G5"); + break; + default: + sprintf(CPU,"Unknown PPC"); + } +#else + // it looks odd to have a switch for two cases, but it leaves room for easy expansion. Odds are that Apple will some day use newer CPUs than i686 + switch (hostInfo.cpu_subtype) { + case CPU_SUBTYPE_PENTPRO: + sprintf(CPU,"i686"); + break; + default: + sprintf(CPU,"Unknown Intel"); + } +#endif + + // get the version of OSX + if( Gestalt( gestaltSystemVersion, &sysVersion ) != noErr ) { + sprintf(OS,"Undetected"); + } else { + + int majorHiNib, majorLoNib, minorNib, bugNib; + + majorHiNib = (sysVersion & 0x0000F000) >> 12; + majorLoNib = (sysVersion & 0x00000F00) >> 8; + minorNib = (sysVersion & 0x000000F0) >> 4; + bugNib = sysVersion & 0x0000000F; + + sprintf(OS, "%d%d.%d.%d", majorHiNib, majorLoNib, minorNib, bugNib); + } + + // make a list of used newgrf files + if (_first_grffile != NULL) { + GRFFile *file; + newgrf[0] = 0; + + + for (file = _first_grffile; file != NULL; file = file->next) { + sprintf(newgrf, "%s %s", newgrf, file->filename); + } + } else { + sprintf(newgrf, "none"); + } + sprintf(buffer, "Please add this info: (tip: copy-paste works)\nCPU: %s, OSX: %s, OpenTTD version: %s\nNewGRF files:%s", CPU, OS, _openttd_revision, newgrf); + return buffer; +} + #ifdef WITH_SDL @@ -40,11 +130,22 @@ void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression ) { const char *buffer = - [[NSString stringWithFormat:@"An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\"%s\"\n\nYou should report this error the OpenTTD developers if you think you found a bug.", - function, file, line, expression] cString]; + [[NSString stringWithFormat:@"An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\"%s\"\n\nYou should report this error the OpenTTD developers if you think you found a bug.\n\n%s", + function, file, line, expression, GetOSString()] cString]; NSLog(@"%s", buffer); + ToggleFullScreen(0); ShowMacDialog( "Assertion Failed", buffer, "Quit" ); // abort so that a debugger has a chance to notice abort(); } + + +void ShowMacErrorDialog(const char *error) +{ + const char *buffer = + [[NSString stringWithFormat:@"Please update to the newest version of OpenTTD\nIf the problem presists, please report this to\nhttp://bugs.openttd.org\n\n%s", GetOSString()] cString]; + ToggleFullScreen(0); + ShowMacDialog(error, buffer, "Quit" ); + abort(); +}