fixed crashes (hoping it's not a merge conflict)

master
Allen Webster 2017-10-31 03:14:24 -04:00
parent 894479bfca
commit 2587feee0e
3 changed files with 106 additions and 83 deletions

View File

@ -923,22 +923,30 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
result.position_start = i; result.position_start = i;
Cpp_Token token = {0};
token.start = state->size;
if (state->token_ptr < state->end_token){
token = *state->token_ptr;
}
if (state->consume_newline){ if (state->consume_newline){
++i; ++i;
state->x = 0; state->x = 0;
state->consume_newline = 0; state->consume_newline = 0;
} }
if (state->in_pp_body){ if (state->in_pp_body){
if (!(state->token_ptr->flags & CPP_TFLAG_PP_BODY)){ if (!(token.flags & CPP_TFLAG_PP_BODY)){
state->in_pp_body = 0; state->in_pp_body = false;
state->wrap_x = state->plane_wrap_x; state->wrap_x = state->plane_wrap_x;
} }
} }
if (!state->in_pp_body){ if (!state->in_pp_body){
if (state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){ if (token.flags & CPP_TFLAG_PP_DIRECTIVE){
state->in_pp_body = 1; state->in_pp_body = true;
state->plane_wrap_x = state->wrap_x; state->plane_wrap_x = state->wrap_x;
state->wrap_x = null_wrap_x; state->wrap_x = null_wrap_x;
} }
@ -967,8 +975,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
i32 line_start = state->line_starts[state->line_index]; i32 line_start = state->line_starts[state->line_index];
b32 still_looping = 0; b32 still_looping = 0;
i32 end = state->token_ptr->start + state->token_ptr->size; i32 end = token.start + token.size;
if (fixed_end_point >= 0 && end > fixed_end_point){ if (fixed_end_point >= 0 && end > fixed_end_point){
end = fixed_end_point; end = fixed_end_point;
} }
@ -1015,7 +1022,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
if (!skipping_whitespace){ if (!skipping_whitespace){
if (!recorded_start_x){ if (!recorded_start_x){
result.start_x = state->x; result.start_x = state->x;
recorded_start_x = 1; recorded_start_x = true;
} }
state->x += adv; state->x += adv;
} }
@ -1028,13 +1035,14 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
state->i = i; state->i = i;
b32 consume_token = 0; b32 consume_token = false;
if (state->token_ptr < state->end_token && i >= state->token_ptr->start + state->token_ptr->size){ if (state->token_ptr < state->end_token && i >= token.start + token.size){
consume_token = 1; consume_token = true;
} }
result.this_token = state->token_ptr; result.this_token = state->token_ptr;
if (consume_token){ if (consume_token){
Assert(state->token_ptr < state->end_token);
switch (state->token_ptr->type){ switch (state->token_ptr->type){
case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_OPEN:
{ {
@ -1088,7 +1096,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
if (!recorded_start_x){ if (!recorded_start_x){
result.start_x = state->x; result.start_x = state->x;
recorded_start_x = 1; recorded_start_x = true;
} }
return(result); return(result);
@ -1262,6 +1270,11 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top]; result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top];
Cpp_Token next_token = {0};
if (wrap_state->token_ptr < wrap_state->end_token){
next_token = *wrap_state->token_ptr;
}
if (wrap_state->token_ptr > wrap_state->token_array.tokens){ if (wrap_state->token_ptr > wrap_state->token_array.tokens){
Cpp_Token prev_token = *(wrap_state->token_ptr-1); Cpp_Token prev_token = *(wrap_state->token_ptr-1);
@ -1286,18 +1299,18 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
} }
} }
switch (wrap_state->token_ptr->type){ switch (next_token.type){
case CPP_TOKEN_BRACE_CLOSE: case CPP_TOKEN_BRACE_OPEN: break; case CPP_TOKEN_BRACE_CLOSE: case CPP_TOKEN_BRACE_OPEN: break;
default: result.shift += statement_continuation_indent; break; default: result.shift += statement_continuation_indent; break;
} }
} }
if (wrap_state->token_ptr->start < next_line_start){ if (next_token.start < next_line_start){
if (wrap_state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){ if (next_token.flags & CPP_TFLAG_PP_DIRECTIVE){
result.shift = 0; result.shift = 0;
} }
else{ else{
switch (wrap_state->token_ptr->type){ switch (next_token.type){
case CPP_TOKEN_BRACE_CLOSE: case CPP_TOKEN_BRACE_CLOSE:
{ {
if (wrap_state->wrap_x.paren_safe_top == 0){ if (wrap_state->wrap_x.paren_safe_top == 0){
@ -1496,8 +1509,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
for (; wrap_state.token_ptr < wrap_state.end_token; ){ for (; wrap_state.token_ptr < wrap_state.end_token; ){
Code_Wrap_Step step = {0}; Code_Wrap_Step step = {0};
b32 emit_comment_position = 0; b32 emit_comment_position = false;
b32 first_word = 1; b32 first_word = true;
if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){ if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){
i32 i = wrap_state.token_ptr->start; i32 i = wrap_state.token_ptr->start;
@ -1626,29 +1639,39 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
step = wrap_state_consume_token(system, font, &wrap_state, next_line_start); step = wrap_state_consume_token(system, font, &wrap_state, next_line_start);
} }
b32 need_to_choose_a_wrap = 0; b32 need_to_choose_a_wrap = false;
if (step.final_x > current_width){ if (step.final_x > current_width){
need_to_choose_a_wrap = 1; need_to_choose_a_wrap = true;
} }
current_shift = get_current_shift(&wrap_state, next_line_start); current_shift = get_current_shift(&wrap_state, next_line_start);
b32 next_token_is_on_line = 0; b32 next_token_is_on_line = false;
if (wrap_state.token_ptr < wrap_state.end_token){
if (wrap_state.token_ptr->start < next_line_start){ if (wrap_state.token_ptr->start < next_line_start){
next_token_is_on_line = 1; next_token_is_on_line = true;
}
} }
i32 next_wrap_position = step.position_end; i32 next_wrap_position = step.position_end;
f32 wrap_x = step.final_x; f32 wrap_x = step.final_x;
if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){ if (next_token_is_on_line){
next_wrap_position = wrap_state.token_ptr->start; if (wrap_state.token_ptr < wrap_state.end_token){
i32 pos_i = wrap_state.token_ptr->start;
if (pos_i > step.position_start && next_wrap_position < pos_i){
next_wrap_position = pos_i;
}
}
} }
if (!need_to_choose_a_wrap){ if (!need_to_choose_a_wrap){
i32 wrappable_score = 1; i32 wrappable_score = 1;
Cpp_Token *this_token = step.this_token; Cpp_Token *this_token = step.this_token;
Cpp_Token *next_token = wrap_state.token_ptr; Cpp_Token *next_token = 0;
if (wrap_state.token_ptr < wrap_state.end_token){
next_token = wrap_state.token_ptr;
}
Cpp_Token_Type this_type = this_token->type; Cpp_Token_Type this_type = this_token->type;
Cpp_Token_Type next_type = CPP_TOKEN_JUNK; Cpp_Token_Type next_type = CPP_TOKEN_JUNK;

View File

@ -42,7 +42,7 @@ system_load_library(Library *library, char *name, Load_Library_Location location
if (!match(extension, DLL)){ if (!match(extension, DLL)){
String full_name = make_fixed_width_string(space); String full_name = make_fixed_width_string(space);
append(&full_name, name); append(&full_name, name);
append(&full_name, "."DLL); append(&full_name, "." DLL);
if (terminate_with_null(&full_name)){ if (terminate_with_null(&full_name)){
name = space; name = space;
} }

View File

@ -227,18 +227,18 @@ sysshared_to_binary_path(String *out_filename, char *filename){
// //
inline void inline void
draw_safe_push(Render_Target *target, i32 size, void *x){ draw_safe_push(Render_Target *t, i32 size, void *x){
if (size + target->size <= target->max){ if (size + t->size <= t->max){
memcpy(target->push_buffer + target->size, x, size); memcpy(t->push_buffer + t->size, x, size);
target->size += size; t->size += size;
} }
} }
#define PutStruct(s,x) draw_safe_push(target, sizeof(s), &x) #define PutStruct(s,x) draw_safe_push(t, sizeof(s), &x)
internal void internal void
draw_push_piece(Render_Target *target, Render_Piece_Combined piece){ draw_push_piece(Render_Target *t, Render_Piece_Combined piece){
if (!target->clip_all){ if (!t->clip_all){
PutStruct(Render_Piece_Header, piece.header); PutStruct(Render_Piece_Header, piece.header);
switch (piece.header.type){ switch (piece.header.type){
@ -263,13 +263,13 @@ draw_push_piece(Render_Target *target, Render_Piece_Combined piece){
}break; }break;
} }
Assert(target->size <= target->max); Assert(t->size <= t->max);
} }
} }
internal void internal void
draw_push_piece_clip(Render_Target *target, i32_Rect clip_box){ draw_push_piece_clip(Render_Target *t, i32_Rect clip_box){
if (!target->clip_all){ if (!t->clip_all){
// TODO(allen): optimize out if there are two clip box changes in a row // TODO(allen): optimize out if there are two clip box changes in a row
Render_Piece_Change_Clip clip; Render_Piece_Change_Clip clip;
Render_Piece_Header header; Render_Piece_Header header;
@ -283,24 +283,24 @@ draw_push_piece_clip(Render_Target *target, i32_Rect clip_box){
} }
internal void internal void
draw_push_clip(Render_Target *target, i32_Rect clip_box){ draw_push_clip(Render_Target *t, i32_Rect clip_box){
Assert(target->clip_top == -1 || fits_inside(clip_box, target->clip_boxes[target->clip_top])); Assert(t->clip_top == -1 || fits_inside(clip_box, t->clip_boxes[t->clip_top]));
Assert(target->clip_top+1 < ArrayCount(target->clip_boxes)); Assert(t->clip_top+1 < ArrayCount(t->clip_boxes));
target->clip_boxes[++target->clip_top] = clip_box; t->clip_boxes[++t->clip_top] = clip_box;
target->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1); t->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(target, clip_box); draw_push_piece_clip(t, clip_box);
} }
internal i32_Rect internal i32_Rect
draw_pop_clip(Render_Target *target){ draw_pop_clip(Render_Target *t){
Assert(target->clip_top > 0); Assert(t->clip_top > 0);
i32_Rect result = target->clip_boxes[target->clip_top]; i32_Rect result = t->clip_boxes[t->clip_top];
--target->clip_top; --t->clip_top;
i32_Rect clip_box = target->clip_boxes[target->clip_top]; i32_Rect clip_box = t->clip_boxes[t->clip_top];
target->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1); t->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(target, clip_box); draw_push_piece_clip(t, clip_box);
return(result); return(result);
} }
@ -319,31 +319,31 @@ link_rendering(){
#define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s) #define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s)
inline void inline void
draw_set_clip(Render_Target *target, i32_Rect clip_box){ draw_set_clip(Render_Target *t, i32_Rect clip_box){
glScissor(clip_box.x0, target->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0); glScissor(clip_box.x0, t->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0);
} }
inline void inline void
draw_bind_texture(Render_Target *target, i32 texid){ draw_bind_texture(Render_Target *t, i32 texid){
if (target->bound_texture != texid){ if (t->bound_texture != texid){
glBindTexture(GL_TEXTURE_2D, texid); glBindTexture(GL_TEXTURE_2D, texid);
target->bound_texture = texid; t->bound_texture = texid;
} }
} }
inline void inline void
draw_set_color(Render_Target *target, u32 color){ draw_set_color(Render_Target *t, u32 color){
if (target->color != color){ if (t->color != color){
target->color = color; t->color = color;
Vec4 c = unpack_color4(color); Vec4 c = unpack_color4(color);
glColor4f(c.r, c.g, c.b, c.a); glColor4f(c.r, c.g, c.b, c.a);
} }
} }
inline void inline void
private_draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){ private_draw_rectangle(Render_Target *t, f32_Rect rect, u32 color){
draw_set_color(target, color); draw_set_color(t, color);
draw_bind_texture(target, 0); draw_bind_texture(t, 0);
glBegin(GL_QUADS); glBegin(GL_QUADS);
{ {
glVertex2f(rect.x0, rect.y0); glVertex2f(rect.x0, rect.y0);
@ -355,10 +355,10 @@ private_draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){
} }
inline void inline void
private_draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){ private_draw_rectangle_outline(Render_Target *t, f32_Rect rect, u32 color){
f32_Rect r = get_inner_rect(rect, .5f); f32_Rect r = get_inner_rect(rect, .5f);
draw_set_color(target, color); draw_set_color(t, color);
draw_bind_texture(target, 0); draw_bind_texture(t, 0);
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
{ {
glVertex2f(r.x0, r.y0); glVertex2f(r.x0, r.y0);
@ -371,11 +371,11 @@ private_draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){
} }
inline void inline void
private_draw_gradient(Render_Target *target, f32_Rect rect, Vec4 color_left, Vec4 color_right){ private_draw_gradient(Render_Target *t, f32_Rect rect, Vec4 color_left, Vec4 color_right){
Vec4 cl = color_left; Vec4 cl = color_left;
Vec4 cr = color_right; Vec4 cr = color_right;
draw_bind_texture(target, 0); draw_bind_texture(t, 0);
glBegin(GL_QUADS); glBegin(GL_QUADS);
{ {
glColor4f(cl.r, cl.g, cl.b, cl.a); glColor4f(cl.r, cl.g, cl.b, cl.a);
@ -433,13 +433,13 @@ get_exact_render_quad(Glyph_Bounds *b, i32 pw, i32 ph, float xpos, float ypos){
} }
inline void inline void
private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){ private_draw_glyph(System_Functions *system, Render_Target *t, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){
Glyph_Data glyph = font_get_glyph(system, font, codepoint); Glyph_Data glyph = font_get_glyph(system, font, codepoint);
if (glyph.tex != 0){ if (glyph.tex != 0){
Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y); Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
draw_set_color(target, color); draw_set_color(t, color);
draw_bind_texture(target, glyph.tex); draw_bind_texture(t, glyph.tex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
{ {
glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1); glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1);
@ -452,7 +452,7 @@ private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font
} }
inline void inline void
private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){ private_draw_glyph_mono(System_Functions *system, Render_Target *t, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){
Glyph_Data glyph = font_get_glyph(system, font, codepoint); Glyph_Data glyph = font_get_glyph(system, font, codepoint);
if (glyph.tex != 0){ if (glyph.tex != 0){
f32 left = glyph.bounds.x0; f32 left = glyph.bounds.x0;
@ -464,8 +464,8 @@ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_
Render_Quad q = get_exact_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y); Render_Quad q = get_exact_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
draw_set_color(target, color); draw_set_color(t, color);
draw_bind_texture(target, glyph.tex); draw_bind_texture(t, glyph.tex);
glBegin(GL_QUADS); glBegin(GL_QUADS);
{ {
glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1); glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1);
@ -478,15 +478,15 @@ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_
} }
inline void inline void
private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){ private_draw_glyph_mono(System_Functions *system, Render_Target *t, Render_Font *font, u32 character, f32 x, f32 y, u32 color){
f32 advance = (f32)font_get_advance(font); f32 advance = (f32)font_get_advance(font);
private_draw_glyph_mono(system, target, font, character, x, y, advance, color); private_draw_glyph_mono(system, t, font, character, x, y, advance, color);
} }
internal void internal void
launch_rendering(System_Functions *system, Render_Target *target){ launch_rendering(System_Functions *system, Render_Target *t){
char *cursor = target->push_buffer; char *cursor = t->push_buffer;
char *cursor_end = cursor + target->size; char *cursor_end = cursor + t->size;
for (; cursor < cursor_end;){ for (; cursor < cursor_end;){
Render_Piece_Header *header = ExtractStruct(Render_Piece_Header); Render_Piece_Header *header = ExtractStruct(Render_Piece_Header);
@ -496,19 +496,19 @@ launch_rendering(System_Functions *system, Render_Target *target){
case piece_type_rectangle: case piece_type_rectangle:
{ {
Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle); Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle);
private_draw_rectangle(target, rectangle->rect, rectangle->color); private_draw_rectangle(t, rectangle->rect, rectangle->color);
}break; }break;
case piece_type_outline: case piece_type_outline:
{ {
Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle); Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle);
private_draw_rectangle_outline(target, rectangle->rect, rectangle->color); private_draw_rectangle_outline(t, rectangle->rect, rectangle->color);
}break; }break;
case piece_type_gradient: case piece_type_gradient:
{ {
Render_Piece_Gradient *gradient = ExtractStruct(Render_Piece_Gradient); Render_Piece_Gradient *gradient = ExtractStruct(Render_Piece_Gradient);
private_draw_gradient(target, gradient->rect, unpack_color4(gradient->left_color), unpack_color4(gradient->right_color)); private_draw_gradient(t, gradient->rect, unpack_color4(gradient->left_color), unpack_color4(gradient->right_color));
}break; }break;
case piece_type_glyph: case piece_type_glyph:
@ -517,7 +517,7 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0); Assert(font != 0);
private_draw_glyph(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}break; }break;
case piece_type_mono_glyph: case piece_type_mono_glyph:
@ -526,7 +526,7 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0); Assert(font != 0);
private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph_mono(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}break; }break;
case piece_type_mono_glyph_advance: case piece_type_mono_glyph_advance:
@ -535,13 +535,13 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0); Assert(font != 0);
private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); private_draw_glyph_mono(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color);
}break; }break;
case piece_type_change_clip: case piece_type_change_clip:
{ {
Render_Piece_Change_Clip *clip = ExtractStruct(Render_Piece_Change_Clip); Render_Piece_Change_Clip *clip = ExtractStruct(Render_Piece_Change_Clip);
draw_set_clip(target, clip->box); draw_set_clip(t, clip->box);
}break; }break;
} }
} }