Fix T68272: Annotations segment fault when use Simplify option

This error was introduced with the array dynamic system for very long stroke.

Now, instead to use a custom code for simplify annotations, it uses the standard simplify BKE function more robust and with better results.

The factor of 0.15f has been set fixed after testing a good result value.
This commit is contained in:
Antonio Vazquez 2019-08-05 20:52:00 +02:00
parent b4a325f535
commit cdeda1fa6c
Notes: blender-bot 2023-02-14 09:48:25 +01:00
Referenced by issue #68272, Blender close when I finish to use annotate and i have option Simplify Stroke active in preferences
Referenced by issue #67199, EEvEE rendered color error
Referenced by issue #66731, Translated texts remain original english
1 changed files with 5 additions and 84 deletions

View File

@ -561,87 +561,6 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
return GP_STROKEADD_INVALID;
}
/* simplify a stroke (in buffer) before storing it
* - applies a reverse Chaikin filter
* - code adapted from etch-a-ton branch
*/
static void gp_stroke_simplify(tGPsdata *p)
{
bGPdata *gpd = p->gpd;
tGPspoint *old_points = (tGPspoint *)gpd->runtime.sbuffer;
short num_points = gpd->runtime.sbuffer_used;
short flag = gpd->runtime.sbuffer_sflag;
short i, j;
/* only simplify if simplification is enabled, and we're not doing a straight line */
if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) {
return;
}
/* don't simplify if less than 4 points in buffer */
if ((num_points <= 4) || (old_points == NULL)) {
return;
}
/* clear buffer (but don't free mem yet) so that we can write to it
* - firstly set sbuffer to NULL, so a new one is allocated
* - secondly, reset flag after, as it gets cleared auto
*/
gpd->runtime.sbuffer = NULL;
gp_session_validatebuffer(p);
gpd->runtime.sbuffer_sflag = flag;
/* macro used in loop to get position of new point
* - used due to the mixture of datatypes in use here
*/
#define GP_SIMPLIFY_AVPOINT(offs, sfac) \
{ \
co[0] += (float)(old_points[offs].x * sfac); \
co[1] += (float)(old_points[offs].y * sfac); \
pressure += old_points[offs].pressure * sfac; \
time += old_points[offs].time * sfac; \
} \
(void)0
/* XXX Here too, do not lose start and end points! */
gp_stroke_addpoint(
p, &old_points->x, old_points->pressure, p->inittime + (double)old_points->time);
for (i = 0, j = 0; i < num_points; i++) {
if (i - j == 3) {
float co[2], pressure, time;
float mco[2];
/* initialize values */
co[0] = 0.0f;
co[1] = 0.0f;
pressure = 0.0f;
time = 0.0f;
/* using macro, calculate new point */
GP_SIMPLIFY_AVPOINT(j, -0.25f);
GP_SIMPLIFY_AVPOINT(j + 1, 0.75f);
GP_SIMPLIFY_AVPOINT(j + 2, 0.75f);
GP_SIMPLIFY_AVPOINT(j + 3, -0.25f);
/* set values for adding */
mco[0] = co[0];
mco[1] = co[1];
/* ignore return values on this... assume to be ok for now */
gp_stroke_addpoint(p, mco, pressure, p->inittime + (double)time);
j += 2;
}
}
gp_stroke_addpoint(p,
&old_points[num_points - 1].x,
old_points[num_points - 1].pressure,
p->inittime + (double)old_points[num_points - 1].time);
/* free old buffer */
MEM_freeN(old_points);
}
/* make a new stroke from the buffer data */
static void gp_stroke_newfrombuffer(tGPsdata *p)
{
@ -839,6 +758,11 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
}
/* Simplify stroke */
if ((U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode != GP_PAINTMODE_DRAW_STRAIGHT)) {
BKE_gpencil_simplify_stroke(gps, 0.15f);
}
/* add stroke to frame */
BLI_addtail(&p->gpf->strokes, gps);
gp_stroke_added_enable(p);
@ -1466,9 +1390,6 @@ static void gp_paint_strokeend(tGPsdata *p)
/* check if doing eraser or not */
if ((p->gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) {
/* simplify stroke before transferring? */
gp_stroke_simplify(p);
/* transfer stroke to frame */
gp_stroke_newfrombuffer(p);
}