serge-rgb / milton

An infinite-canvas paint program
GNU General Public License v3.0
1.53k stars 133 forks source link

Fix a crash #66

Closed gsass1 closed 7 years ago

gsass1 commented 7 years ago

When the canvas is unsaved, selecting the "New Canvas" dialog in the menu, choosing either option can sometimes crash the program, specifically on https://github.com/serge-rgb/milton/blob/04354239d31f479ed245de7e7a3bd1570e26a80b/src/gui.cc#L424

This happens because milton_reset_canvas_and_set_default calls arena_bootstrap on milton_state->canvas, but due to the nature of the arena system this may actually change the pointer of canvas.

In milton_imgui_tick there is a local var canvas that gets assigned at the beginning of the function. When milton_state->canvas changes, the local canvas is not updated and will cause a crash because it points to a faulty memory address.

What my patch does is update the canvas variable right after the canvas is reset. This fixes the issue.

serge-rgb commented 7 years ago

Nice catch! Thanks for the detailed PR.