diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 2dd6599cecf..75b8e2f218d 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -602,9 +602,12 @@ static int text_run_script(bContext *C, ReportList *reports) /* Don't report error messages while live editing */ if (!is_live) { - if (text->curl != curl_prev || curc_prev != text->curc) { - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + /* text may have freed its self */ + if (CTX_data_edit_text(C) == text) { + if (text->curl != curl_prev || curc_prev != text->curc) { + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + } } BKE_report(reports, RPT_ERROR, "Python script fail, look in the console for now..."); diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index f89d8904a16..85f6163c721 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -53,6 +53,7 @@ #include "BLI_path_util.h" #include "BLI_fileops.h" +#include "BLI_listbase.h" #include "BLI_math_base.h" #include "BLI_string.h" #include "BLI_string_utf8.h" @@ -383,6 +384,7 @@ typedef struct { static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports, const short do_jump) { + Main *bmain_old = CTX_data_main(C); PyObject *main_mod = NULL; PyObject *py_dict = NULL, *py_result = NULL; PyGILState_STATE gilstate; @@ -461,7 +463,11 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, if (!py_result) { if (text) { if (do_jump) { - python_script_error_jump_text(text); + /* ensure text is valid before use, the script may have freed its self */ + Main *bmain_new = CTX_data_main(C); + if ((bmain_old == bmain_new) && (BLI_findindex(&bmain_new->text, text) != -1)) { + python_script_error_jump_text(text); + } } } BPy_errors_to_report(reports);