fix for crash executing a python script.

nice obscure case, when a script executes, frees its self (by loading a file for eg), then has a python error.

... in this case blender would fetch the python exception and attempt to move the cursor in the freed textblock to the error line, crashing blender.
This commit is contained in:
Campbell Barton
2012-09-23 06:25:39 +00:00
parent 3e9a09d385
commit 552cd4b7e7
2 changed files with 13 additions and 4 deletions

View File

@@ -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...");

View File

@@ -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);