Fix #114892: crash opening old files with text objects

Exposed by 16e4eeb9c0.

In (rare) occasions, a Curve's `CharInfo` can be NULL.
This also crashed going into editmode on affected text objects in
previous versions, however opening and rendering these files was still
fine.

In 4.0, opening those kind of files crashed.

It is not entirely clear how this can happen (there are comments in code
dating back to 97df61a7e5 mentioning "old file", there might be other
reasons, too), still, avoiding the crash on file open seems like good
practice.

Pull Request: https://projects.blender.org/blender/blender/pulls/114916
This commit is contained in:
Philipp Oeser 2023-11-16 09:42:34 +01:00 committed by Philipp Oeser
parent d46d1bbe6a
commit 578b479998
1 changed files with 6 additions and 4 deletions

View File

@ -1863,10 +1863,12 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
const int curvetype = BKE_curve_type_get(curve);
if (curvetype == OB_FONT) {
CharInfo *info = curve->strinfo;
for (int i = curve->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr > 0) {
/** CharInfo mat_nr used to start at 1, unlike mesh & nurbs, now zero-based. */
info->mat_nr--;
if (info != nullptr) {
for (int i = curve->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr > 0) {
/** CharInfo mat_nr used to start at 1, unlike mesh & nurbs, now zero-based. */
info->mat_nr--;
}
}
}
}