LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_error.c File Reference

Functions

int big_error (int big_error_code, const char *format,...)
 
void warning (int block, const char *format,...)
 
void lg_override_warning_timeout (int timeout)
 
void lg_reset_warning_timeout ()
 
uint64_t lg_log_time ()
 
void lg_set_error_context (const char *file, unsigned int line, const char *func, const char *txt, int code)
 
int lg_get_error_context_code ()
 
const char * lg_get_full_error_context ()
 
void lg_clear_error_context ()
 
void lg_save_error_context (LG_ErrorContext *err_ctx)
 
void lg_restore_error_context (LG_ErrorContext *err_ctx)
 
int lg_push_error_context (LG_ErrorContext *err_ctx)
 
LG_ErrorContextlg_pop_error_context ()
 
void sig_handler (int sig_num, siginfo_t *sig_info, void *context)
 
void set_sig_handler ()
 
void lg_print_out_error_codes ()
 
void test_big_error (int test)
 

Variables

static LG_ErrorContext backup0
 
static LG_ErrorContextbackup = &backup0
 

Detailed Description

 === Errors handling ===

 Also check out these macros in lg_error.h:
#define CHECK_GL_E lg_check_gl_errors((int64_t)lg_log_time(), __FILE__, __LINE__, __func__)
#define CHECK_GL_E_2 {if (lg_check_gl_errors((int64_t)lg_log_time(), __FILE__, __LINE__, __func__) != LG_OK) exit(-1);}
#define __chkp__(pointer, string, ret_value) {if (pointer == NULL) {INFO_ERR("%s == NULL\n", string); return ret_value;}}
#define __chkp2__(pointer, string, exit_1) {if (pointer == NULL) {INFO_ERR("%s == NULL\n", string); goto exit_1;}}
#define __chkv__(x, string_x, y, string_y, exit_1) {if (x == y) {INFO_ERR("%s == %s\n", string_x, string_y); goto exit_1;}}
#define NESF(line_num) INFO_ERR("No errors so far ... (line %d)\n", line_num)
 Usage example:
// Checking for OpenGL errors
static int lg_init_line_renderer_2d()
{
// ...
LG_VBO_bind(&(renderer->line_vbo));
// ...
return CHECK_GL_E;
}
// Checking for NULL pointers
void *new_thing() {
// ...
void *mem = malloc2(64 * 1024);
__chkp__(mem, "mem", NULL)
// ...
return mem;
}
// Debugging stuff
{
// ...
NESF(__LINE__)
// ...
NESF(__LINE__)
// ...
}
void LG_VBO_bind(LG_VBO *vbo)
Definition lg_vbo.c:109
void * malloc2(size_t size)
Definition str_mem.c:183
 TODO: complete the doc

Function Documentation

◆ big_error()

int big_error ( int  big_error_code,
const char *  format,
  ... 
)

This func's prototype is in libetm/error.h. This func is not defined in Libetm but in application and it handles CRITICAL ERRORS from both Libetm and application.

 NUA:

 "*** CRITICAL ERROR ***"
 if (big_error_code > LIBETM_LASTERRORCODE && big_error_code <= LG_LASTERRORCODE) {
    bla bla
 } else if (big_error_code >  LG_LASTERRORCODE) {
    bla bla
 }

◆ warning()

void warning ( int  block,
const char *  format,
  ... 
)

This func's prototype is in libetm/error.h. This func is not defined in Libetm but in application and it handles WARNINGS from both Libetm and application.

Will popup and wait for WARNING_TIMEOUT ms if no_block == TRUE, then close. Otherwise, will block until an appropriate keyboard/mouse action happens.

You can use BLOCK/NO_BLOCK helpers.

◆ lg_override_warning_timeout()

void lg_override_warning_timeout ( int  timeout)

Override warning timeout default value (= WARNING_TIMEOUT defined in lg_error.c)

Parameters
timeoutNew timeout in ms

◆ lg_reset_warning_timeout()

void lg_reset_warning_timeout ( )

Reset warning timeout to default value (= WARNING_TIMEOUT defined in lg_error.c)

◆ lg_log_time()

uint64_t lg_log_time ( )

Log time for NOW - func name could be lg_now_time()

◆ lg_set_error_context()

void lg_set_error_context ( const char *  file,
unsigned int  line,
const char *  func,
const char *  txt,
int  code 
)

Set error context

Trying to find a way to trace back error origin

◆ lg_get_error_context_code()

int lg_get_error_context_code ( )

Get error context code

◆ lg_get_full_error_context()

const char * lg_get_full_error_context ( )

Get full error context code

◆ lg_clear_error_context()

void lg_clear_error_context ( )

Clear error context

◆ lg_save_error_context()

void lg_save_error_context ( LG_ErrorContext err_ctx)

Save error context

◆ lg_restore_error_context()

void lg_restore_error_context ( LG_ErrorContext err_ctx)

Restore error context

◆ lg_push_error_context()

int lg_push_error_context ( LG_ErrorContext err_ctx)

Push error context

◆ lg_pop_error_context()

LG_ErrorContext * lg_pop_error_context ( )

Pop error context

◆ sig_handler()

void sig_handler ( int  sig_num,
siginfo_t *  sig_info,
void *  context 
)

Set up the Unix signals handler

You must define app_sig_handler() somewhere in your app, so that you can get useful debugging info and exit properly

void app_sig_handler(int sig_num, const char *sig_txt)
{
INFO_ERR("%s received - will probably exit\n", sig_txt);
big_error(LG_SIG_START + sig_num, "%s received - this is a *bug*", sig_txt);
}
int big_error(int big_error_code, const char *format,...)
Definition lg_error.c:117

lg_error_code enum is defined in libgame.h

◆ set_sig_handler()

void set_sig_handler ( )

Handling a few UNIX signals

◆ lg_print_out_error_codes()

void lg_print_out_error_codes ( )

Print out error codes

◆ test_big_error()

void test_big_error ( int  test)

Testing big_error()