Skip to content

Commit 749a51b

Browse files
committed
realloc crash fix
1 parent ab555be commit 749a51b

5 files changed

Lines changed: 23 additions & 19 deletions

File tree

GUI.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ void GUI_destroy()
223223
current_state.conf->do_render = 0;
224224
while(current_state.rendering) Sleep(5);
225225

226-
current_state.conf->active=0;
227-
228226
for(struct GUI_Window *start = List_start(current_state.windows),
229227
*end = List_end(current_state.windows);
230228
start < end; start++)
231229
GUI_windows_remove(start->id);
232230

231+
current_state.conf->active=0;
232+
233233
List_free(current_state.windows);
234234

235235
GUI_impl_destroy();
@@ -331,7 +331,7 @@ union U_GUI_Window_id_wrapper
331331
void *ptr;
332332
};
333333

334-
static void f_List_reserve_callback_marks(List l, enum E_CALLBACK_MSG msg, void *arg)
334+
static void f_List_reserve_callback_stop_render(List l, enum E_CALLBACK_MSG msg, void *arg)
335335
{
336336
union U_GUI_Window_id_wrapper wrapped_id = (union U_GUI_Window_id_wrapper)arg;
337337
GUI_Window_id id = wrapped_id.id;
@@ -365,12 +365,11 @@ GUI_Window_id GUI_windows_append()
365365
struct GUI_Window *win = List_append(current_state.windows, NULL);
366366

367367
win->id=current_id++;
368-
win->l = List_create(sizeof(S_TYPE));
369368
win->marks = List_create(sizeof(struct GUI_Mark));
370369

371370
//set callback for realloc
372371
union U_GUI_Window_id_wrapper wrapped_id = {win->id};
373-
List_reserve_callback(win->marks, f_List_reserve_callback_marks, wrapped_id.ptr);
372+
List_reserve_callback(win->marks, f_List_reserve_callback_stop_render, wrapped_id.ptr);
374373

375374
win->opacity=1.0f;
376375
win->do_render = 1;
@@ -422,6 +421,9 @@ void GUI_Window_set_list(GUI_Window_id id, List l)
422421
win->do_render = 0;
423422
while(win->rendering) Sleep(5);
424423
win->l = l;
424+
//set callback for realloc
425+
union U_GUI_Window_id_wrapper wrapped_id = {id};
426+
List_reserve_callback(win->l, f_List_reserve_callback_stop_render, wrapped_id.ptr);
425427
List_clear(win->marks);
426428
win->do_render = tmp;
427429
}

GUI_impl_unix.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ struct Rect get_screen_dimensions()
3636
void Draw_begin()
3737
{
3838
if(current_state.conf->active){
39-
// get current window size
40-
XGetWindowAttributes(d,w,&attr);
41-
rect.right=attr.width;
42-
rect.bottom=attr.height;
43-
buffer = XCreatePixmap(d,w,rect.right,rect.bottom, 24);
44-
45-
Draw_Rect(&rect, (struct Color){0,0,0});
46-
XSetForeground(d, gc, 0);
39+
// get current window size
40+
XGetWindowAttributes(d,w,&attr);
41+
rect.right=attr.width;
42+
rect.bottom=attr.height;
43+
buffer = XCreatePixmap(d,w,rect.right,rect.bottom, 24);
44+
45+
Draw_Rect(&rect, (struct Color){0,0,0});
46+
XSetForeground(d, gc, 0);
4747
}
4848
}
4949

5050
void Draw_Rect(struct Rect *rect, struct Color col)
5151
{
52-
if(current_state.conf->active){
52+
if(buffer){
5353
XGCValues v;
5454
v.foreground=RGB(col.r, col.g, col.b);
5555
GC color = XCreateGC(d,buffer,GCForeground,&v);
@@ -72,6 +72,7 @@ void Draw_end()
7272
{
7373
XCopyArea(d, buffer, w, gc, 0,0, rect.right, rect.bottom, 0, 0);
7474
XFreePixmap(d, buffer);
75+
buffer=0;
7576

7677
}
7778

@@ -85,7 +86,7 @@ static void* GUI_thread_proc(void *unused){
8586

8687
XMapWindow(d,w);
8788

88-
current_state.conf->active=1;
89+
current_state.conf->active=1;
8990

9091
while(current_state.conf->active){
9192
// while(XNextEvent(d, &e)){

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ if BUILD_NSPIRE
1616
_EXTRA_CLEANUP+= $(PROGRAMS:.elf=.tns)
1717
SortTest_CFLAGS=-Ofast -funsafe-math-optimizations -Wall
1818
else
19-
SortTest_CFLAGS_x=-Ofast -mavx2 -Wall -m64 -s -funsafe-math-optimizations
20-
SortTest_CFLAGS=-g -fsanitize=address
19+
SortTest_CFLAGS=-Ofast -mavx2 -Wall -m64 -s -funsafe-math-optimizations
20+
SortTest_CFLAGS_x=-g -fsanitize=address
2121
endif
2222

2323
if BUILD_LINUX

Sort.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ void _ReculinSort(List l, int iter)
317317
}
318318

319319

320+
GUI_Window_do_render(u, 0);
321+
GUI_Window_do_render(o, 0);
320322
//printf("%d | %d\n", urlaub.filled, output.filled);
321323
if(!List_size(urlaub)){
322324

SortTest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ int main(int argc, char** argv){
231231
}
232232

233233
printf(OUT_FORMAT,Conf.SortAlgs[i].name,Conf.SortAlgs[i].time/CLOCKS_PER_SEC,Conf.SortAlgs[i].swap,Conf.SortAlgs[i].comp);
234-
if(List_size(l)>0)
235-
List_free(l);
234+
List_free(l);
236235
}
237236
end:
238237
if(gui_conf.activate)

0 commit comments

Comments
 (0)