SLUDGE: replace char* by Common::String for error messages
This commit is contained in:
parent
8152793d09
commit
fe773c1beb
4 changed files with 32 additions and 78 deletions
|
@ -2569,8 +2569,7 @@ builtIn(setThumbnailSize) {
|
|||
return BR_ERROR;
|
||||
trimStack(fun->stack);
|
||||
if (thumbWidth < 0 || thumbHeight < 0 || thumbWidth > winWidth || thumbHeight > winHeight) {
|
||||
char buff[50];
|
||||
sprintf(buff, "%d x %d", thumbWidth, thumbHeight);
|
||||
Common::String buff = thumbWidth + " x " + thumbHeight;
|
||||
fatal("Invalid thumbnail size", buff);
|
||||
return BR_ERROR;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#if 0
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
|
@ -41,8 +35,8 @@ namespace Sludge {
|
|||
|
||||
const char emergencyMemoryMessage[] = "Out of memory displaying error message!";
|
||||
|
||||
static char *fatalMessage = NULL;
|
||||
static char *fatalInfo = joinStrings("Initialisation error! Something went wrong before we even got started!", "");
|
||||
static Common::String fatalMessage;
|
||||
static Common::String fatalInfo = "Initialisation error! Something went wrong before we even got started!";
|
||||
|
||||
extern int numResourceNames /* = 0*/;
|
||||
extern char * *allResourceNames /*= NULL*/;
|
||||
|
@ -60,20 +54,20 @@ const char *resourceNameFromNum(int i) {
|
|||
}
|
||||
|
||||
bool hasFatal() {
|
||||
if (fatalMessage)
|
||||
if (!fatalMessage.empty())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void displayFatal() {
|
||||
if (fatalMessage) {
|
||||
if (!fatalMessage.empty()) {
|
||||
#if 0
|
||||
msgBox("SLUDGE v" TEXT_VERSION " fatal error!", fatalMessage);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void warning(const char *l) {
|
||||
void warning(const Common::String &l) {
|
||||
#if 0
|
||||
setGraphicsWindow(false);
|
||||
msgBox("SLUDGE v" TEXT_VERSION " non-fatal indigestion report", l);
|
||||
|
@ -81,40 +75,12 @@ void warning(const char *l) {
|
|||
}
|
||||
|
||||
void registerWindowForFatal() {
|
||||
delete[] fatalInfo;
|
||||
fatalInfo =
|
||||
joinStrings("There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", "");
|
||||
fatalInfo = "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.";
|
||||
}
|
||||
|
||||
#if 0
|
||||
extern SDL_Event quit_event;
|
||||
#endif
|
||||
|
||||
int inFatal(const char *str) {
|
||||
error(str);
|
||||
delete []str;
|
||||
#if 0
|
||||
FILE *fatFile = fopen("fatal.txt", "wt");
|
||||
if (fatFile) {
|
||||
fprintf(fatFile, "FATAL:\n%s\n", str);
|
||||
fclose(fatFile);
|
||||
}
|
||||
|
||||
fatalMessage = copyString(str);
|
||||
if (fatalMessage == NULL)
|
||||
fatalMessage = copyString("Out of memory");
|
||||
|
||||
int inFatal(const Common::String &str) {
|
||||
killSoundStuff();
|
||||
|
||||
#if defined(HAVE_GLES2)
|
||||
EGL_Close();
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
atexit(displayFatal);
|
||||
exit(1);
|
||||
#endif
|
||||
error(str.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -126,45 +92,30 @@ int checkNew(const void *mem) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void setFatalInfo(const char *userFunc, const char *BIF) {
|
||||
delete[] fatalInfo;
|
||||
fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38];
|
||||
if (fatalInfo)
|
||||
sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF);
|
||||
debug(kSludgeDebugFatal, "%s", fatalInfo);
|
||||
void setFatalInfo(const Common::String &userFunc, const Common::String &BIF) {
|
||||
fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF;
|
||||
debug(kSludgeDebugFatal, "%s", fatalInfo.c_str());
|
||||
}
|
||||
|
||||
void setResourceForFatal(int n) {
|
||||
resourceForFatal = n;
|
||||
}
|
||||
|
||||
int fatal(const char *str1) {
|
||||
int fatal(const Common::String &str1) {
|
||||
if (numResourceNames && resourceForFatal != -1) {
|
||||
const char *r = resourceNameFromNum(resourceForFatal);
|
||||
char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) + 14];
|
||||
if (checkNew(newStr)) {
|
||||
sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1);
|
||||
inFatal(newStr);
|
||||
} else
|
||||
fatal(emergencyMemoryMessage);
|
||||
Common::String r = resourceNameFromNum(resourceForFatal);
|
||||
Common::String newStr = fatalInfo + "\nResource: " + r + "\n\n" + str1;
|
||||
inFatal(newStr);
|
||||
} else {
|
||||
char *newStr = new char[strlen(str1) + strlen(fatalInfo) + 3];
|
||||
if (checkNew(newStr)) {
|
||||
sprintf(newStr, "%s\n\n%s", fatalInfo, str1);
|
||||
inFatal(newStr);
|
||||
} else
|
||||
fatal(emergencyMemoryMessage);
|
||||
Common::String newStr = fatalInfo + "\n\n" + str1;
|
||||
inFatal(newStr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fatal(const char *str1, const char *str2) {
|
||||
char *newStr = new char[strlen(str1) + strlen(str2) + 2];
|
||||
if (checkNew(newStr)) {
|
||||
sprintf(newStr, "%s %s", str1, str2);
|
||||
fatal(newStr);
|
||||
} else
|
||||
fatal(emergencyMemoryMessage);
|
||||
int fatal(const Common::String &str1, const Common::String &str2) {
|
||||
Common::String newStr = str1 + " " + str2;
|
||||
fatal(newStr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,21 +22,23 @@
|
|||
#ifndef SLUDGE_NEWFATAL_H
|
||||
#define SLUDGE_NEWFATAL_H
|
||||
|
||||
#include "common/str.h"
|
||||
|
||||
#include "sludge/errors.h"
|
||||
|
||||
namespace Sludge {
|
||||
|
||||
bool hasFatal();
|
||||
|
||||
int fatal(const char *str);
|
||||
int fatal(const char *str1, const char *str2);
|
||||
int fatal(const Common::String &str);
|
||||
int fatal(const Common::String &str1, const Common::String &str2);
|
||||
int checkNew(const void *mem);
|
||||
void displayFatal();
|
||||
void registerWindowForFatal();
|
||||
void setFatalInfo(const char *userFunc, const char *BIF);
|
||||
void warning(const char *l);
|
||||
void setFatalInfo(const Common::String &userFunc, const Common::String &BIF);
|
||||
void warning(const Common::String &l);
|
||||
void setResourceForFatal(int n);
|
||||
char *resourceNameFromNum(int i);
|
||||
const char *resourceNameFromNum(int i);
|
||||
|
||||
} // End of namespace Sludge
|
||||
|
||||
|
|
|
@ -591,8 +591,10 @@ variableStack *stackFindLast(variableStack *hunt) {
|
|||
bool getValueType(int &toHere, variableType vT, const variable &v) {
|
||||
//if (! v) return false;
|
||||
if (v.varType != vT) {
|
||||
char *e1 = joinStrings("Can only perform specified operation on a value which is of type ", typeName[vT]);
|
||||
char *e2 = joinStrings("... value supplied was of type ", typeName[v.varType]);
|
||||
Common::String e1 = "Can only perform specified operation on a value which is of type ";
|
||||
e1 += typeName[vT];
|
||||
Common::String e2 = "... value supplied was of type ";
|
||||
e2 += typeName[v.varType];
|
||||
fatal(e1, e2);
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue