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/* Checking for NULL pointers v2 */
18#define __chkp__(pointer, string, ret_value) {if (pointer == NULL) {INFO_ERR("%s == NULL\n", string); return ret_value;}}
19
20/* Where is this used ? */
21#define STH_WRONG_HERE \
22 { \
23 static int i = 0; \
24 if (i == 0) { \
25 INFO_OUT("VARO TÄSSÄ\n%s [%s: %d] %s(): jotain pitää korjata\n", UTF8_RW_ROUNDED_ARROW, __FILE__, __LINE__, __func__) \
26 i++; \
27 } \
28 }
29
30/* Debugging stuff (trivial) */
31#define DEBUG_ENTER_FUNC INFO_OUT("\n\nDEBUG **** %s() ****\n\n", __func__)
32#define DEBUG_ENTER_FUNC2(str) INFO_OUT("\n\nDEBUG **** %s() -> %s ****\n\n", __func__, str)
33#define DEBUG_CHK_PTR(ptr) \
34 { \
35 if (ptr == NULL) { \
36 INFO_OUT("\n\nDEBUG **** [%s: %d] %s() -> POINTER IS NULL ****\n\n", __FILE__, __LINE__, __func__) \
37 exit(-1); \
38 } \
39 }
40
41/* Adding timestamps to error logs on Linux */
42/*
43 * TODO: it would be actually more correct to change:
44 * - TIME_FILE_LINE_FUNC_STR to TIME_FILE_LINE_FUNC
45 * and
46 * - TIME_FILE_LINE_FUNC_STR2 to TIME_FILE_LINE_FUNC_STR
47 * but:
48 * - There is already (uncorrectly) FILE_LINE_FUNC_STR in libetm.h
49 * which should be also changed
50 * - It's not working so far
51 */
52
53long long lg_log_time();
54
55#ifndef ANDROID_V
56 #define TIME_FILE_LINE_FUNC_STR "%lld [%s: %d] %s(): ", lg_log_time(), __FILE__, __LINE__, __func__
57 // STH WRONG HERE - #define TIME_FILE_LINE_FUNC_STR2 "[%lld %s: %d] %s(): %s", lg_log_time(), __FILE__, __LINE__, __func__
58 #define INFO_ERR2(...) \
59 {\
60 fprintf(STD_ERR, TIME_FILE_LINE_FUNC_STR);\
61 fprintf(STD_ERR, __VA_ARGS__);\
62 fflush(STD_ERR);\
63 }
64#endif
65
66#define LG_ERR_CTX_FILE_MAXLEN 63
67#define LG_ERR_CTX_FUNC_MAXLEN 63
68#define LG_ERR_CTX_TXT_MAXLEN 1023
69#define LG_ERR_CTX_CODE_NA (-100000) /* Really not sure what to pick */
70#define LG_ERR_CTX_STR_MAXLEN 2048 /* Must contain all of the above - for snprintf() */
71#define LG_ERR_CTX_FORMAT "[%s: %d] %s(): %s (code = %d)"
72
73typedef struct {
74 char file[LG_ERR_CTX_FILE_MAXLEN + 1]; /* Not the full path */
75 unsigned int line;
76 char func[LG_ERR_CTX_FUNC_MAXLEN + 1];
77 char txt[LG_ERR_CTX_TXT_MAXLEN + 1];
78 int code;
80
81/* This is actually an almost duplicate of Libetm/error.h: struct ErrSt (code/str) */
82typedef struct {
83 int code;
84 const char *txt;
86
87enum {OOM_MALLOC2_TEST, OOM_MALLOC3_TEST, OOM_MALLOC3_TEST2, INVPTR_FREE2_TEST, INVPTR_FREE3_TEST, SEGFAULT_TEST, DIVBYZERO_TEST};
88
89void lg_override_warning_timeout(int);
90
91void lg_reset_warning_timeout();
92
93void lg_set_error_context(const char *, unsigned int, const char *, const char *, int);
94
95int lg_get_error_context_code();
96
97const char *lg_get_full_error_context();
98
99void lg_clear_error_context();
100
101void lg_save_error_context(LG_ErrorContext *);
102
103void lg_restore_error_context(LG_ErrorContext *);
104
105#ifndef WIN32_V
106void sig_handler(int, siginfo_t *, void *);
107
108void set_sig_handler();
109
110extern void app_sig_handler(int, const char *);
111#endif
112
114
115void test_big_error(int);
116
117#endif /* LG_ERROR_H */
void set_sig_handler()
Definition lg_error.c:344
void sig_handler(int sig_num, siginfo_t *sig_info, void *context)
Definition lg_error.c:317
void test_big_error(int test)
Definition lg_error.c:424
void lg_print_out_error_codes()
Definition lg_error.c:402
Definition lg_error.h:73
Definition lg_error.h:82