Fix crash when having multiple text objects sharing the same curve datablock
Issue was caused by BKE_vfont_to_curve() modifying curve->nurbs list which gave threading issues. Now added BKE_vfont_to_curve_nubase() which operates on a given nurbs list base which is local in do_makeDispListCurveTypes(). By the looks of it it wouldn't give speed regression because previously it also was creating nurbs for every font object sharing the same curve data.
This commit is contained in:
@@ -83,6 +83,9 @@ void BKE_vfont_free(struct VFont *sc);
|
|||||||
struct VFont *BKE_vfont_builtin_get(void);
|
struct VFont *BKE_vfont_builtin_get(void);
|
||||||
struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
|
struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
|
||||||
|
|
||||||
|
bool BKE_vfont_to_curve_nubase(struct Main *bmain, struct Scene *scene, struct Object *ob,
|
||||||
|
struct ListBase *nubase, int mode, struct CharTrans **r_chartransdata);
|
||||||
|
|
||||||
bool BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode,
|
bool BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode,
|
||||||
struct CharTrans **r_chartransdata);
|
struct CharTrans **r_chartransdata);
|
||||||
|
|
||||||
|
|||||||
@@ -1374,10 +1374,12 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
|
|||||||
if (ob->curve_cache->path) free_path(ob->curve_cache->path);
|
if (ob->curve_cache->path) free_path(ob->curve_cache->path);
|
||||||
ob->curve_cache->path = NULL;
|
ob->curve_cache->path = NULL;
|
||||||
|
|
||||||
if (ob->type == OB_FONT)
|
if (ob->type == OB_FONT) {
|
||||||
BKE_vfont_to_curve(G.main, scene, ob, FO_EDIT, NULL);
|
BKE_vfont_to_curve_nubase(G.main, scene, ob, &nubase, FO_EDIT, NULL);
|
||||||
|
}
|
||||||
BKE_nurbList_duplicate(&nubase, BKE_curve_nurbs_get(cu));
|
else {
|
||||||
|
BKE_nurbList_duplicate(&nubase, BKE_curve_nurbs_get(cu));
|
||||||
|
}
|
||||||
|
|
||||||
if (!forOrco)
|
if (!forOrco)
|
||||||
curve_calc_modifiers_pre(scene, ob, &nubase, forRender, renderResolution);
|
curve_calc_modifiers_pre(scene, ob, &nubase, forRender, renderResolution);
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ static VChar *find_vfont_char(VFontData *vfd, unsigned int character)
|
|||||||
return BLI_ghash_lookup(vfd->characters, SET_UINT_IN_POINTER(character));
|
return BLI_ghash_lookup(vfd->characters, SET_UINT_IN_POINTER(character));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, int charidx, short mat_nr)
|
static void build_underline(Curve *cu, ListBase *nubase, float x1, float y1, float x2, float y2, int charidx, short mat_nr)
|
||||||
{
|
{
|
||||||
Nurb *nu2;
|
Nurb *nu2;
|
||||||
BPoint *bp;
|
BPoint *bp;
|
||||||
@@ -324,11 +324,11 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
|
|||||||
copy_v4_fl4(bp[3].vec, x1, y2, 0.0f, 1.0f);
|
copy_v4_fl4(bp[3].vec, x1, y2, 0.0f, 1.0f);
|
||||||
|
|
||||||
nu2->bp = bp;
|
nu2->bp = bp;
|
||||||
BLI_addtail(&(cu->nurb), nu2);
|
BLI_addtail(nubase, nu2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buildchar(Main *bmain, Curve *cu, unsigned int character, CharInfo *info,
|
static void buildchar(Main *bmain, Curve *cu, ListBase *nubase, unsigned int character, CharInfo *info,
|
||||||
float ofsx, float ofsy, float rot, int charidx)
|
float ofsx, float ofsy, float rot, int charidx)
|
||||||
{
|
{
|
||||||
BezTriple *bezt1, *bezt2;
|
BezTriple *bezt1, *bezt2;
|
||||||
@@ -450,7 +450,7 @@ static void buildchar(Main *bmain, Curve *cu, unsigned int character, CharInfo *
|
|||||||
bezt2++;
|
bezt2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLI_addtail(&(cu->nurb), nu2);
|
BLI_addtail(nubase, nu2);
|
||||||
}
|
}
|
||||||
|
|
||||||
nu1 = nu1->next;
|
nu1 = nu1->next;
|
||||||
@@ -495,8 +495,8 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode,
|
bool BKE_vfont_to_curve_nubase(Main *bmain, Scene *scene, Object *ob, ListBase *nubase,
|
||||||
struct CharTrans **r_chartransdata)
|
int mode, struct CharTrans **r_chartransdata)
|
||||||
{
|
{
|
||||||
Curve *cu = ob->data;
|
Curve *cu = ob->data;
|
||||||
EditFont *ef = cu->editfont;
|
EditFont *ef = cu->editfont;
|
||||||
@@ -1020,7 +1020,7 @@ makebreak:
|
|||||||
|
|
||||||
if (mode == FO_EDIT) {
|
if (mode == FO_EDIT) {
|
||||||
/* make nurbdata */
|
/* make nurbdata */
|
||||||
BKE_nurbList_free(&cu->nurb);
|
BKE_nurbList_free(nubase);
|
||||||
|
|
||||||
ct = chartransdata;
|
ct = chartransdata;
|
||||||
for (i = 0; i < slen; i++) {
|
for (i = 0; i < slen; i++) {
|
||||||
@@ -1037,7 +1037,7 @@ makebreak:
|
|||||||
}
|
}
|
||||||
/* We do not want to see any character for \n or \r */
|
/* We do not want to see any character for \n or \r */
|
||||||
if (cha != '\n' && cha != '\r')
|
if (cha != '\n' && cha != '\r')
|
||||||
buildchar(bmain, cu, cha, info, ct->xof, ct->yof, ct->rot, i);
|
buildchar(bmain, cu, nubase, cha, info, ct->xof, ct->yof, ct->rot, i);
|
||||||
|
|
||||||
if ((info->flag & CU_CHINFO_UNDERLINE) && (cu->textoncurve == NULL) && (cha != '\n') && (cha != '\r')) {
|
if ((info->flag & CU_CHINFO_UNDERLINE) && (cu->textoncurve == NULL) && (cha != '\n') && (cha != '\r')) {
|
||||||
float ulwidth, uloverlap = 0.0f;
|
float ulwidth, uloverlap = 0.0f;
|
||||||
@@ -1054,7 +1054,8 @@ makebreak:
|
|||||||
|
|
||||||
twidth = char_width(cu, che, info);
|
twidth = char_width(cu, che, info);
|
||||||
ulwidth = cu->fsize * ((twidth * (1.0f + (info->kern / 40.0f))) + uloverlap);
|
ulwidth = cu->fsize * ((twidth * (1.0f + (info->kern / 40.0f))) + uloverlap);
|
||||||
build_underline(cu, ct->xof * cu->fsize, ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize,
|
build_underline(cu, nubase,
|
||||||
|
ct->xof * cu->fsize, ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize,
|
||||||
ct->xof * cu->fsize + ulwidth,
|
ct->xof * cu->fsize + ulwidth,
|
||||||
ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize - cu->ulheight * cu->fsize,
|
ct->yof * cu->fsize + (cu->ulpos - 0.05f) * cu->fsize - cu->ulheight * cu->fsize,
|
||||||
i, info->mat_nr);
|
i, info->mat_nr);
|
||||||
@@ -1081,3 +1082,13 @@ finally:
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode,
|
||||||
|
struct CharTrans **r_chartransdata)
|
||||||
|
{
|
||||||
|
Curve *cu = (Curve *) ob->data;
|
||||||
|
|
||||||
|
BLI_assert(ob->type == OB_FONT);
|
||||||
|
|
||||||
|
return BKE_vfont_to_curve_nubase(bmain, scene, ob, &cu->nurb, mode, r_chartransdata);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user