28 #include "ascension/context.h" |
28 #include "ascension/context.h" |
29 #include "ascension/error.h" |
29 #include "ascension/error.h" |
30 #include "ascension/utils.h" |
30 #include "ascension/utils.h" |
31 |
31 |
32 #include <cx/buffer.h> |
32 #include <cx/buffer.h> |
|
33 #include <cx/printf.h> |
33 #include <GL/gl.h> |
34 #include <GL/gl.h> |
34 |
35 |
35 void asc_error_cchar(char const* text) { |
36 void asc_error_impl(const char* file, unsigned line, char const* fmt, ...) { |
36 asc_error_cxstr(cx_str(text)); |
37 asc_set_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); |
37 } |
|
38 |
38 |
39 void asc_error_cuchar(unsigned char const* text) { |
39 // write to error buffer |
40 asc_error_cxstr(cx_str((char const*)text)); |
40 va_list args; |
41 } |
41 va_start(args, fmt); |
|
42 CxBuffer* buf = &asc_context.error_buffer; |
|
43 size_t bufpos = buf->pos; |
|
44 int written = cx_vfprintf(buf, cxBufferWriteFunc, fmt, args); |
|
45 cxBufferPut(buf, '\n'); |
|
46 va_end(args); |
42 |
47 |
43 void asc_error_cxstr(cxstring text) { |
48 // also print to stderr |
44 if (text.length == 0) return; |
49 // avoid double-formatting, get it directly from the buffer |
45 |
50 fprintf(stderr, "[ERROR %s %u] %.*s\n", |
46 // write error to debug output |
51 file, line, written, buf->space+bufpos); |
47 asc_dprintf("ERROR: %.*s", (int)text.length, text.ptr); |
|
48 |
|
49 // write error to buffer |
|
50 CxBuffer* buf = &asc_context.error_buffer; |
|
51 cxBufferWrite(text.ptr, 1, text.length, buf); |
|
52 cxBufferPut(buf, '\n'); |
|
53 |
|
54 asc_set_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); |
|
55 } |
52 } |
56 |
53 |
57 bool asc_has_error(void) { |
54 bool asc_has_error(void) { |
58 return asc_test_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); |
55 return asc_test_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); |
59 } |
56 } |
98 glerr = "stack overflow"; |
95 glerr = "stack overflow"; |
99 break; |
96 break; |
100 default: |
97 default: |
101 glerr = "unknown GL error"; |
98 glerr = "unknown GL error"; |
102 } |
99 } |
103 cxmutstr msg = cx_strcat(3, message, CX_STR(" GL Error: "), cx_str(glerr)); |
100 asc_error("%s\nGL Error: %s", message, glerr); |
104 asc_error_cxstr(cx_strcast(msg)); |
|
105 cx_strfree(&msg); |
|
106 } |
101 } |
107 |
102 |
108 int asc_error_catch_all_gl(void) { |
103 int asc_error_catch_all_gl(void) { |
109 GLenum error; |
104 GLenum error; |
110 int ret = 0; |
105 int ret = 0; |