Made rencache warn on exhausting command buffer instead of panicing
This commit is contained in:
parent
4c2c03ed4d
commit
9bf0ed2419
|
@ -78,13 +78,13 @@ static RenRect merge_rects(RenRect a, RenRect b) {
|
||||||
|
|
||||||
static Command* push_command(int type, int size) {
|
static Command* push_command(int type, int size) {
|
||||||
Command *cmd = (Command*) (command_buf + command_buf_idx);
|
Command *cmd = (Command*) (command_buf + command_buf_idx);
|
||||||
memset(cmd, 0, sizeof(Command));
|
|
||||||
int n = command_buf_idx + size;
|
int n = command_buf_idx + size;
|
||||||
if (n > COMMAND_BUF_SIZE) {
|
if (n > COMMAND_BUF_SIZE) {
|
||||||
fprintf(stderr, "Fatal error in " __FILE__ ": exhausted command buffer\n");
|
fprintf(stderr, "Warning: (" __FILE__ "): exhausted command buffer\n");
|
||||||
exit(EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
}
|
||||||
command_buf_idx = n;
|
command_buf_idx = n;
|
||||||
|
memset(cmd, 0, sizeof(Command));
|
||||||
cmd->type = type;
|
cmd->type = type;
|
||||||
cmd->size = size;
|
cmd->size = size;
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@ -121,9 +121,11 @@ void rencache_set_clip_rect(RenRect rect) {
|
||||||
void rencache_draw_rect(RenRect rect, RenColor color) {
|
void rencache_draw_rect(RenRect rect, RenColor color) {
|
||||||
if (!rects_overlap(screen_rect, rect)) { return; }
|
if (!rects_overlap(screen_rect, rect)) { return; }
|
||||||
Command *cmd = push_command(DRAW_RECT, sizeof(Command));
|
Command *cmd = push_command(DRAW_RECT, sizeof(Command));
|
||||||
|
if (cmd) {
|
||||||
cmd->rect = rect;
|
cmd->rect = rect;
|
||||||
cmd->color = color;
|
cmd->color = color;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor color) {
|
int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor color) {
|
||||||
|
@ -136,11 +138,13 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c
|
||||||
if (rects_overlap(screen_rect, rect)) {
|
if (rects_overlap(screen_rect, rect)) {
|
||||||
int sz = strlen(text) + 1;
|
int sz = strlen(text) + 1;
|
||||||
Command *cmd = push_command(DRAW_TEXT, sizeof(Command) + sz);
|
Command *cmd = push_command(DRAW_TEXT, sizeof(Command) + sz);
|
||||||
|
if (cmd) {
|
||||||
memcpy(cmd->text, text, sz);
|
memcpy(cmd->text, text, sz);
|
||||||
cmd->color = color;
|
cmd->color = color;
|
||||||
cmd->font = font;
|
cmd->font = font;
|
||||||
cmd->rect = rect;
|
cmd->rect = rect;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return x + rect.width;
|
return x + rect.width;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue