Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2021-05-04 15:46:32 +0300
committerSebastian Parborg <darkdefende@gmail.com>2021-05-04 16:11:20 +0300
commitd0b3f9c81b031f19e0ecfdacad359d76dcddaebb (patch)
tree870b221668c3499c0fa6c22439886dd87f41b870 /source/blender/blenkernel/intern/text.c
parent4599cea15dcf7563bfbcb8be148ef5f89cf2dddd (diff)
Fix T87489: Text Data-Blocks get deleted on Recursive Purge
Text data block were not considered special in the recursive purge function. So they would get deleted if they had no actual users. To fix this we instead make text data block use "fake user" so that addon authors can specify script files that should be removed if nothing is using it anymore. Per default, new text object have "fake user" set. So functionality wise, the user has to explicitly specify that they want the text object to be purge-able. Reviewed By: Bastien Differential Revision: http://developer.blender.org/D10983
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r--source/blender/blenkernel/intern/text.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 944e01321ce..27f5593c2ca 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -171,6 +171,9 @@ static void text_free_data(ID *id)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
+ if (id->us < 1 && !BLO_write_is_undo(writer)) {
+ return;
+ }
Text *text = (Text *)id;
/* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */
@@ -231,8 +234,6 @@ static void text_blend_read_data(BlendDataReader *reader, ID *id)
}
text->flags = (text->flags) & ~TXT_ISEXT;
-
- id_us_ensure_real(&text->id);
}
IDTypeInfo IDType_ID_TXT = {
@@ -293,8 +294,10 @@ Text *BKE_text_add(Main *bmain, const char *name)
Text *ta;
ta = BKE_id_new(bmain, ID_TXT, name);
- /* Texts always have 'real' user (see also read code). */
- id_us_ensure_real(&ta->id);
+ /* Texts have no users by default... Set the fake user flag to ensure that this text block
+ * doesn't get deleted by default when cleaning up data blocks. */
+ id_us_min(&ta->id);
+ id_fake_user_set(&ta->id);
return ta;
}
@@ -468,7 +471,7 @@ bool BKE_text_reload(Text *text)
* \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.
+ * \note text data-blocks have no real user but have 'fake user' enabled by default
*/
Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal)
{
@@ -489,9 +492,8 @@ 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 have no user by default... Only the 'real' user flag. */
- id_us_ensure_real(&ta->id);
id_us_min(&ta->id);
+ id_fake_user_set(&ta->id);
BLI_listbase_clear(&ta->lines);
ta->curl = ta->sell = NULL;