Fix T71260: GPencil crash when drawing very long lines
There were two problems: 1) When the buffer was reallocate, the pointer was corrupted. 2) Short variables were too small to hold long lines.
This commit is contained in:
parent
018b754fb6
commit
782f36d6a8
Notes:
blender-bot
2023-02-14 10:29:32 +01:00
Referenced by issue #71260, GPencil: Blender crashes after Malloc returns null while drawing a line when use lot of points
|
@ -3660,7 +3660,6 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
tGPsdata *p = op->customdata;
|
||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||
GP_Sculpt_Guide *guide = &p->scene->toolsettings->gp_sculpt.guide;
|
||||
tGPspoint *points = (tGPspoint *)p->gpd->runtime.sbuffer;
|
||||
|
||||
/* default exit state - pass through to support MMB view nav, etc. */
|
||||
int estate = OPERATOR_PASS_THROUGH;
|
||||
|
@ -3969,6 +3968,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
int size_after = p->gpd->runtime.sbuffer_used;
|
||||
|
||||
/* Last point of the event is always real (not fake). */
|
||||
tGPspoint *points = (tGPspoint *)p->gpd->runtime.sbuffer;
|
||||
tGPspoint *pt = &points[size_after - 1];
|
||||
pt->tflag &= ~GP_TPOINT_FAKE;
|
||||
|
||||
|
|
|
@ -2530,8 +2530,8 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
|
|||
|
||||
/* Ensure the SBuffer (while drawing stroke) size is enough to save all points of the stroke */
|
||||
tGPspoint *ED_gpencil_sbuffer_ensure(tGPspoint *buffer_array,
|
||||
short *buffer_size,
|
||||
short *buffer_used,
|
||||
int *buffer_size,
|
||||
int *buffer_used,
|
||||
const bool clear)
|
||||
{
|
||||
tGPspoint *p = NULL;
|
||||
|
|
|
@ -292,8 +292,8 @@ void ED_gpencil_select_toggle_all(struct bContext *C, int action);
|
|||
|
||||
/* Ensure stroke sbuffer size is enough */
|
||||
struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array,
|
||||
short *buffer_size,
|
||||
short *buffer_used,
|
||||
int *buffer_size,
|
||||
int *buffer_used,
|
||||
const bool clear);
|
||||
/* Tag all scene grease pencil object to update. */
|
||||
void ED_gpencil_tag_scene_gpencil(struct Scene *scene);
|
||||
|
|
|
@ -447,17 +447,16 @@ typedef struct bGPdata_Runtime {
|
|||
* - buffer must be initialized before use, but freed after
|
||||
* whole paint operation is over
|
||||
*/
|
||||
/** Number of elements currently used in cache. */
|
||||
short sbuffer_used;
|
||||
/** Flags for stroke that cache represents. */
|
||||
short sbuffer_sflag;
|
||||
/** Number of elements currently used in cache. */
|
||||
int sbuffer_used;
|
||||
/** Number of total elements available in cache. */
|
||||
short sbuffer_size;
|
||||
char _pad[4];
|
||||
int sbuffer_size;
|
||||
|
||||
/** Number of control-points for stroke. */
|
||||
int tot_cp_points;
|
||||
char _pad1_[4];
|
||||
char _pad_[4];
|
||||
/** Array of control-points for stroke. */
|
||||
bGPDcontrolpoint *cp_points;
|
||||
} bGPdata_Runtime;
|
||||
|
|
Loading…
Reference in New Issue