Fix T82849: Assert When Unlinking "Edit Source" Text Data-block.

Simplify and sanitize handling of usercounts for Text IDs generated
trhough `BKE_text_load_ex`.
This commit is contained in:
Bastien Montagne 2020-11-23 11:56:40 +01:00
parent 401612b8e1
commit 64513df8b6
Notes: blender-bot 2023-02-14 09:19:09 +01:00
Referenced by issue #82849, Assert When Unlinking "Edit Source" Text Data-block
4 changed files with 11 additions and 6 deletions

View File

@ -459,6 +459,12 @@ bool BKE_text_reload(Text *text)
return true;
}
/** Load a text file.
*
* \param is_internal If \a true, this text data-block only exists in memory, not as a file on
* disk.
*
* \note: text data-blocks have no user by default, only the 'real user' flag. */
Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal)
{
unsigned char *buffer;
@ -478,8 +484,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
}
ta = BKE_libblock_alloc(bmain, ID_TXT, BLI_path_basename(filepath_abs), 0);
/* Texts always have 'real' user (see also read code). */
/* Texts have no user by default... Only the 'real' user flag. */
id_us_ensure_real(&ta->id);
id_us_min(&ta->id);
BLI_listbase_clear(&ta->lines);
ta->curl = ta->sell = NULL;
@ -511,6 +518,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
return ta;
}
/** Load a text file.
*
* \note: text data-blocks have no user by default, only the 'real user' flag. */
Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
{
return BKE_text_load_ex(bmain, file, relpath, false);

View File

@ -1316,7 +1316,6 @@ static int editsource_text_edit(bContext *C,
if (text == NULL) {
text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
id_us_ensure_real(&text->id);
}
if (text == NULL) {

View File

@ -338,8 +338,6 @@ static int text_open_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", str);
text = BKE_text_load_ex(bmain, str, BKE_main_blendfile_path(bmain), internal);
/* Texts have no user by default... Only the 'real' user flag. */
id_us_min(&text->id);
if (!text) {
if (op->customdata) {

View File

@ -543,8 +543,6 @@ static Text *rna_Main_texts_load(Main *bmain,
errno = 0;
txt = BKE_text_load_ex(bmain, filepath, BKE_main_blendfile_path(bmain), is_internal);
/* Texts have no user by default... Only the 'real' user flag. */
id_us_min(&txt->id);
if (!txt) {
BKE_reportf(reports,