Error Definitions

Contains all the error codes and macros to control error logging and return values.

Summary
Error DefinitionsContains all the error codes and macros to control error logging and return values.
Definitions
Precompiler Options
Default Values
Macros
STRINGIZE(s)Use this to write out a precompiler attribute as a char*.
ErrorsContains only a single variable responsible for returning and signaling a fatal error
Variables
tErrorThis is used to specify a fatal error and is used to fall out of the program when detected.
LoggerContains the FileLogger class and the static log file that is opened at the beginning of the program
External Variables
LOGFileLogger type that’s used for all the logging during the running of the program
FileLoggerUsed to log everything during the runtime of the program.
Functions
FileLoggerJust initializes the class into an invalid state
FileLoggerOpens a file for input.
OpenFileOpens a file for input
CloseFileCloses up the opened file and puts the class into an invalid state
operator<<
~FileLoggerCloses the file.
Variables
_Streamstd::fstream The stream that links to the filename for logging
_Mutexboost::recursive_mutex that protects the class from multiple threads accessing the _Stream at the same time.
Error Handling
Definitions
Error LevelsDefine these in the top of your program before <errdef.h> to control what types of errors are logged and what aren’t.
Fatal Error CodesAll of the fatal errors send an error code into Errors::tError that are defined by one of these definitions.
Main Program
game.cpp
d3d.cpp
ddraw.cpp
startup.cpp
gdi.cpp
resources.cpp
Macros
LOG_FATALUsed to log a fatal error into the static FileLogger Logger::LOG.

Definitions

Precompiler Options

WRITE_ERRORSDefine this to write errors to a file
LOG_WINDOWDefine this to write errors to a dedicated log window

Default Values

ERROR_FILENAME”runlog.txt” Filename for the logfile to save to
LINE_MAX1000 Maximum size of a line to read at one time
BUFF_MAX50000 Maximum size of the log output window’s buffer

Macros

STRINGIZE(s)

Use this to write out a precompiler attribute as a char*.

Errors

namespace Errors

Contains only a single variable responsible for returning and signaling a fatal error

Summary
Variables
tErrorThis is used to specify a fatal error and is used to fall out of the program when detected.

Variables

tError

extern int volatile tError

This is used to specify a fatal error and is used to fall out of the program when detected.

Logger

namespace Logger

Contains the FileLogger class and the static log file that is opened at the beginning of the program

Summary
External Variables
LOGFileLogger type that’s used for all the logging during the running of the program

External Variables

LOG

FileLogger type that’s used for all the logging during the running of the program

extern FileLogger   LOG;

FileLogger

class FileLogger

Used to log everything during the runtime of the program.  Is thread safe and can be controlled directly for greater control or very long, unbroken streams.

Summary
Functions
FileLoggerJust initializes the class into an invalid state
FileLoggerOpens a file for input.
OpenFileOpens a file for input
CloseFileCloses up the opened file and puts the class into an invalid state
operator<<
~FileLoggerCloses the file.
Variables
_Streamstd::fstream The stream that links to the filename for logging
_Mutexboost::recursive_mutex that protects the class from multiple threads accessing the _Stream at the same time.

Functions

FileLogger

FileLogger() : Valid(false)

Just initializes the class into an invalid state

FileLogger

FileLogger(char *logName,
std::ios::openmode mode) : Valid(false)

Opens a file for input.

Parameters

logNameCHAR* of the name of the file to open.
modestd::ios::openmode for the type of access that should be used for the filename

OpenFile

int OpenFile(char *logName,
std::ios::openmode mode)

Opens a file for input

Parameters

logNameCHAR* of the name of the file to open.
modestd::ios::openmode for the type of access that should be used for the filename

CloseFile

void CloseFile()

Closes up the opened file and puts the class into an invalid state

operator<<

template <typename T> std::fstream & operator<< (T d)

Writes to the opened file using standard fstream operater<< logic.

Parameters

dtypename T for any type that can be operator<< to a fstream.

Returns

std::fstream reference that will allow for the normal operator<< datastring syntax.

~FileLogger

~FileLogger()

Closes the file.

Variables

_Stream

std::fstream _Stream

std::fstream The stream that links to the filename for logging

_Mutex

boost::recursive_mutex _Mutex

boost::recursive_mutex that protects the class from multiple threads accessing the _Stream at the same time.

Error Handling

Summary
Definitions
Error LevelsDefine these in the top of your program before <errdef.h> to control what types of errors are logged and what aren’t.
Fatal Error CodesAll of the fatal errors send an error code into Errors::tError that are defined by one of these definitions.
Main Program
game.cpp
d3d.cpp
ddraw.cpp
startup.cpp
gdi.cpp
resources.cpp
Macros
LOG_FATALUsed to log a fatal error into the static FileLogger Logger::LOG.

Definitions

Error Levels

Define these in the top of your program before <errdef.h> to control what types of errors are logged and what aren’t.

ERRLVL_FATALFatal errors cause an application to abort.  Default behavior.
ERRLVL_ERRORErrors that can still alow the application to run
ERRLVL_WARNINGWarnings are potential problems that don’t cause errors
ERRLVL_INFOInfo describes the progress of the application with coarse information
ERRLVL_DEBUGDebug is fine grained information for debugger application behavior

Fatal Error Codes

All of the fatal errors send an error code into Errors::tError that are defined by one of these definitions.

Main Program

ERR_TOP100.  Errors at the beginning of the program while still creating windows.
ERR_TOP_LOGFILE110.  Errors opening the log file.
ERR_TOP_THREAD_GAMEINIT120.  Error creating a thread for game_inti.  Obsolete
ERR_END_THREADTERMINATION300.  Error terminating the running thread.  Deadlock?
ERR_UNDEFINED1000.  An undefined error.

game.cpp

ERR_GAMEINIT_NOTREADY1050.  Error in game_init with startup not being ready
ERR_GAMEMAIN_NOTREADY1100.  Error running game_main loop when startup is not ready

d3d.cpp

ERR_D3DINIT_INTERFACE1200.  Error creating an interface to DirectX
ERR_D3DINIT_NOVALIDPIXELFORMAT1210.  Error finding a valid pixel format
ERR_D3DINIT_NOVALIDBPP1220.  Error with an invalid bits per pixel
ERR_D3DINIT_DEVICE1250.  Error Creating a D3D device
ERR_D3DINIT_NOVALIDFORMAT1260.  Error creating a valid back buffer pixel format
ERR_D3DINIT_NOTVALID1290.  Error obtaining valid interfaces, unknown reason
ERR_D3DENUM_ENUMMODES1300.  Error EnumAdapterDisplayModes off the main d3d device interface

ddraw.cpp

ERR_DDRAWINIT_GDM1500.  Error getting current display mode description
ERR_DDRAWINIT_SCL1510.  Error setting the cooperative level with windows
ERR_DDRAWINIT_CSPRIM1520.  Error creating a primary surface
ERR_DDRAWINIT_CC1530.  Error creating a clipper
ERR_DDRAWINIT_SETHWND1540.  Error setting a clipper to the main window
ERR_DDRAWINIT_SETCLIP1550.  Error setting a clipper
ERR_DDRAWINIT_CSBACK1560.  Error creating a back buffer surface
ERR_DDRAWINIT_SDM1570.  Error setting a display mode
ERR_DDRAWINIT_GSD1580.  Error getting a surface description
ERR_DDRAWRESTORE_CC1530.  Error creating a clipper
ERR_DDRAWRESTORE_SETHWND1540.  Error setting a clipper to the main window
ERR_DDRAWRESTORE_SETCLIP1550.  Error setting a clipper
ERR_DDRAWRESTORE_CSBACK1560.  Error creating a back buffer surface
ERR_DDRAWRESTORE_SDM1570.  Error setting a display mode
ERR_DDRAWRESTORE_GSD1580.  Error getting a surface description
ERR_DDRAWRESIZE_CC1600.  Error creating a clipper
ERR_DDRAWRESIZE_SETCLIP1610.  Error setting a clipper
ERR_DDRAWRESIZE_CSBACK1620.  Error creating a back buffer surface

startup.cpp

ERR_STARTUP_NOMEMORY2000.  Error allocating memory
ERR_STARTUP_D3DFAILED2100.  Error creating D3D Interface
ERR_STARTUP_DDRAWFAILED2200.  Error creating DDraw Interface

gdi.cpp

ERR_GDI_FATALDEBUG2300.  Error with GDI, Fatal debug message received

resources.cpp

ERR_RESOURCE_INVALIDCALL2500.  A Call to an object was made without a valid object

Macros

LOG_FATAL

Used to log a fatal error into the static FileLogger Logger::LOG.  Only defined if the error level is FATAL or above (which is default behavior).

#define LOG_FATAL(x) { boost::recursive_mutex::scoped_lock l(LOG._Mutex); LOG << "FATAL: " << x << endl; };

Parameters

xThis is the string that can be operator<< to a std::fstream.
namespace Errors
Contains only a single variable responsible for returning and signaling a fatal error
extern int volatile tError
This is used to specify a fatal error and is used to fall out of the program when detected.
namespace Logger
Contains the FileLogger class and the static log file that is opened at the beginning of the program
class FileLogger
Used to log everything during the runtime of the program.
FileLogger() : Valid(false)
Just initializes the class into an invalid state
int OpenFile(char *logName,
std::ios::openmode mode)
Opens a file for input
void CloseFile()
Closes up the opened file and puts the class into an invalid state
~FileLogger()
Closes the file.
std::fstream _Stream
std::fstream The stream that links to the filename for logging
boost::recursive_mutex _Mutex
boost::recursive_mutex that protects the class from multiple threads accessing the _Stream at the same time.
FileLogger type that’s used for all the logging during the running of the program
Close