LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_error.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
3 * All rights reserved
4 */
5
6#ifndef LG_ERROR_H
7#define LG_ERROR_H
8
9/* GL errors checking */
10#define CHECK_GL_E lg_check_gl_errors(lg_log_time(), __FILE__ , __LINE__, __func__)
11
12#define CHECK_GL_E_2 {if (lg_check_gl_errors(lg_log_time(), __FILE__, __LINE__, __func__) != LG_OK) exit(-1);}
13
14/* Checking for NULL pointers */
15#define CHECKV_R(what, ret_value) {if (what == NULL) {INFO_ERR("NULL pointer\n") return ret_value;}}
16
17/* Where is this used ? */
18#define STH_WRONG_HERE \
19 { \
20 static int i = 0; \
21 if (i == 0) { \
22 INFO_OUT("VARO TÄSSÄ\n%s [%s: %d] %s(): jotain pitää korjata\n", UTF8_RW_ROUNDED_ARROW, __FILE__, __LINE__, __func__) \
23 i++; \
24 } \
25 }
26
27/* Debugging stuff (trivial) */
28#define DEBUG_ENTER_FUNC INFO_OUT("\n\nDEBUG **** %s() ****\n\n", __func__)
29#define DEBUG_ENTER_FUNC2(str) INFO_OUT("\n\nDEBUG **** %s() -> %s ****\n\n", __func__, str)
30#define DEBUG_CHK_PTR(ptr) \
31 { \
32 if (ptr == NULL) { \
33 INFO_OUT("\n\nDEBUG **** [%s: %d] %s() -> POINTER IS NULL ****\n\n", __FILE__, __LINE__, __func__) \
34 exit(-1); \
35 } \
36 }
37
38/* Adding timestamps to error logs on Linux */
39/*
40 * TODO: it would be actually more correct to change:
41 * - TIME_FILE_LINE_FUNC_STR to TIME_FILE_LINE_FUNC
42 * and
43 * - TIME_FILE_LINE_FUNC_STR2 to TIME_FILE_LINE_FUNC_STR
44 * but:
45 * - There is already (uncorrectly) FILE_LINE_FUNC_STR in libetm.h
46 * which should be also changed
47 * - It's not working so far
48 */
49
50long long lg_log_time();
51
52#ifndef ANDROID_V
53 #define TIME_FILE_LINE_FUNC_STR "%lld [%s: %d] %s(): ", lg_log_time(), __FILE__ , __LINE__, __func__
54 // STH WRONG HERE - #define TIME_FILE_LINE_FUNC_STR2 "[%lld %s: %d] %s(): %s", lg_log_time(), __FILE__ , __LINE__, __func__
55 #define INFO_ERR2(...) \
56 {\
57 fprintf(STD_ERR, TIME_FILE_LINE_FUNC_STR);\
58 fprintf(STD_ERR, __VA_ARGS__);\
59 fflush(STD_ERR);\
60 }
61#endif
62
63#define LG_ERR_CTX_FILE_MAXLEN 63
64#define LG_ERR_CTX_FUNC_MAXLEN 63
65#define LG_ERR_CTX_TXT_MAXLEN 1023
66#define LG_ERR_CTX_CODE_NA (-100000) /* Really not sure what to pick */
67#define LG_ERR_CTX_STR_MAXLEN 2048 /* Must contain all of the above - for snprintf() */
68#define LG_ERR_CTX_FORMAT "[%s: %d] %s(): %s (code = %d)"
69
70typedef struct {
71 char file[LG_ERR_CTX_FILE_MAXLEN + 1]; /* Not the full path */
72 unsigned int line;
73 char func[LG_ERR_CTX_FUNC_MAXLEN + 1];
74 char txt[LG_ERR_CTX_TXT_MAXLEN + 1];
75 int code;
77
78/* This is actually an almost duplicate of Libetm/error.h: struct ErrSt (code/str) */
79typedef struct {
80 int code;
81 const char *txt;
83
84enum {OOM_MALLOC2_TEST, OOM_MALLOC3_TEST, OOM_MALLOC3_TEST2, INVPTR_FREE2_TEST, INVPTR_FREE3_TEST, SEGFAULT_TEST, DIVBYZERO_TEST};
85
87
89
90void lg_set_error_context(const char *, unsigned int, const char *, const char *, int);
91
93
94const char *lg_get_full_error_context();
95
97
99
101
102#ifndef WIN32_V
103void sig_handler(int, siginfo_t *, void *);
104
105void set_sig_handler();
106
107extern void app_sig_handler(int, const char *);
108#endif
109
111
112void test_big_error(int);
113
114#endif /* LG_ERROR_H */
void set_sig_handler()
Definition lg_error.c:307
void lg_set_error_context(const char *file, unsigned int line, const char *func, const char *txt, int code)
Definition lg_error.c:143
const char * lg_get_full_error_context()
Definition lg_error.c:167
void lg_override_warning_timeout(int timeout)
Definition lg_error.c:115
void lg_clear_error_context()
Definition lg_error.c:180
int lg_get_error_context_code()
Definition lg_error.c:157
void sig_handler(int sig_num, siginfo_t *sig_info, void *context)
Definition lg_error.c:280
void test_big_error(int test)
Definition lg_error.c:387
void lg_print_out_error_codes()
Definition lg_error.c:365
long long lg_log_time()
Definition lg_error.c:131
void lg_reset_warning_timeout()
Definition lg_error.c:123
void lg_restore_error_context(LG_ErrorContext *err_ctx)
Definition lg_error.c:204
void lg_save_error_context(LG_ErrorContext *err_ctx)
Definition lg_error.c:196
Definition lg_error.h:70
Definition lg_error.h:79