-
Notifications
You must be signed in to change notification settings - Fork 3
Error Management
This section is meant to explain our error codes and why they were triggered in the first place ! First, they are defined in an enum from enums.h as :
typedef enum e_status
{
NOTHING,
...
NB_ERRORS
} t_status;
Each macro except E_P
, E_P_NAME
and E_FLOAT
which are deprecated, NB_ERRORS
which is used to allocate memory for messages and NOTHING
, DEATH
and WIN
which are game-states at program termination so it fall in the same function call as those errors, are used in the current version of the program and every single error is linked to a message defined in env.h. So, when the program encounters an error it uses our clean()
function prototyped as :
void clean(t_env *env, uint8_t error)
env
points to the structure that stores almost everything from our program (defined in structs.h so does the allocated memory and the error message array. Given an error
defined in enum t_status
, clean()
frees used memory and display the right message on the standard output before exit()
with error
as parameter. As explained in README.md under "Error management" section you can retrieve the termination code using the following command in your shell :
$> echo $?
-
10 :
E_BMP_PARSE
In our graphical output, we use external ressources such as Windows Bitmaps (.bmp) to get a nicer result. We use our own BMP Parser to load these files into memory and several errors can occur during this process. If data can't be retrieved through
bmp_to_array()
a non-zero value is returned this way we know that the requested asset wasn't loaded and can't be accessed afterwards.
-
11 :
E_BKGD
Our program handles few resolutions (1280x720p, 1366x768p, 1440x900p and 1920x1080p), the original trigger of this error was if the background asset from the main menu couldn't be loaded, since we changed the way we loaded assets during the development, it is now triggered if the requested resolution isn't supported by our program.
-
12 :
E_MALLOC
malloc()
can fail to allocate requested space in memory, due to this fact we must check that the returned address isn'tNULL
. If so, the program integrity can't be ensured and accessing this memory can lead to segmentation faults.
-
28 :
E_THREAD
To get a higher frame-rate, our program uses
libpthread
to parallelize graphic and audio computations. As stated by the man page ofpthread_create()
, which is the function to create a new thread, this process can fail. If so, the thread isn't created and can't be used afterwards.
This project uses SDL2 to get a graphic output and SDL2_TTF, a SDL2 Framework which allow to display text inside windows generated via SDL2.
-
2 :
E_SDL_INIT
As stated in the API Documentation of
SDL_Init()
, which is the function used to enable a connexion between our program and SDL2, several errors can occur during this process. If so, connexion to the API isn't made and the program can't use it afterwards.
-
3 :
E_SDL_WIN
As stated in the API Documentation of
SDL_CreateWindow()
, which is the function used to create a window and get its address, this process can fail. If so, the program can't have a graphic output.
-
4 :
E_SDL_WINSURF
As stated in the API Documentation of
SDL_GetWindowSurface()
, which is the function to retrieve the address of window's screen data (colors), this process can fail. If so, the program can't access to the screen data either to modify or display it.
-
5 :
E_SDL_UPDATE
As stated in the API Documentation of
SDL_UpdateWindowSurface()
, which is the function to reflect any changes to the surface on the screen, this process can fail. If so, the screen isn't updated and the last surface changes are possibly lost.
-
6 :
E_TTF_INIT
As stated in the API Documentation of
TTF_Init()
, which is the function used to enable a connexion between our program and SDL2_TTF, several errors can occur during this process. If so connexion to the API isn't made and the program can't use it afterwards.
-
7 :
E_TTF_FONT
As stated in the API Documentation of
TTF_OpenFont()
, which is the function to load a True Type Font (.ttf) to write the requested text using its atlas, this process can fail. If so, the font can't be used to write text.
-
8 :
E_TTF_RENDER
As stated in the API Documentation of
TTF_RenderText_Blended()
, which is the function to write text on a surface, this process can fail. If so, the requested text isn't copied on a surface and can't be pasted on the screen afterwards.
-
9 :
E_SDL_BLIT
As stated in the API Documentation of
SDL_BlitSurface()
, which is the function to copy data from one surface to another from a given offset, this process can fail. If so, data isn't pasted on the main surface and is definitely lost.
E_AUDIO_DRIVER,29
E_AUDIO_OPEN,38
E_AUDIO_CLOSE,39
E_DEVICE_OPEN,40
E_DEVICE_CLOSE,41
Since our map is a plain text file (example map available here), we must ensure that a lot of data in it is valid at some point during the parsing because the user is able to modify the map data itself. See our map format to fix the following errors by hand.
-
1 :
E_FILENAME
Since we read files line by line, we need to avoid files like
/dev/random
or/dev/null
that have a null or low probability of newline byte (0x0A) in them. So every data-file handled by our program must have a ".data" extension.
-
14 :
E_P_FS_LINE
This error is triggered when the header information of the map isn't correctly formatted.
-
15 :
E_P_VERTEX
This error is triggered when one misformatted vertex declaration is encountered.
-
16 :
E_P_PLAYER
This error is triggered when the player location is misformatted.
-
17 :
E_P_SECTOR
This error is triggered when one misformatted sector declaration is encountered.
-
18 :
E_P_BLANK
This error is triggered when one non-informative line (either a blank one or a comment) contains junk bytes.
-
20 :
E_P_OPEN
This error is triggered when
open()
failed to retrieve the filedescriptor of the given file.
-
21 :
E_P_GNL
ft_get_next_line()
is our own function to read on filedescriptors line by line, this process can fail at different levels and need to be handled to avoid segmentation faults afterwards. If this error occurs it means that the requested line couldn't be retrieved from the given filedescriptor.
-
22 :
E_P_CLOSE
This error is triggered when
close()
failed close the given file.
-
23 :
E_P_NO_PLAYER
This error is triggered when the player location is incorrect.
-
24 :
E_P_TOTAL
This error is triggered when the amount of vertices is invalid (e.g negative or null).
-
25 :
E_P_NB_VERTEX
This error is triggered when **either the amount of vertices isn't enough to build a polygon or doesn't match the map header information.
-
26 :
E_P_NB_SECTOR
This error is triggered when the amount of sectors doesn't match the map header information.
-
27 :
E_P_NO_TOTAL
This error is triggered when the "total" line is missing from the parsed map, critical informations within it makes the building process impossible.
E_EDIT_ENTITY,31
E_EDIT_PORTAL,32
E_EDIT_SECTOR,33
E_EDIT_SECT_PORTAL,34
E_EDIT_TEXT,35
E_EDIT_VERTEX,36