[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50821] trunk/blender/source/blender: fix for crash executing a python script.
Campbell Barton
ideasman42 at gmail.com
Sun Sep 23 08:25:39 CEST 2012
Revision: 50821
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50821
Author: campbellbarton
Date: 2012-09-23 06:25:39 +0000 (Sun, 23 Sep 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/editors/space_text/text_ops.c
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c 2012-09-23 05:33:23 UTC (rev 50820)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c 2012-09-23 06:25:39 UTC (rev 50821)
@@ -602,9 +602,12 @@
/* 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...");
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2012-09-23 05:33:23 UTC (rev 50820)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2012-09-23 06:25:39 UTC (rev 50821)
@@ -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 @@
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 @@
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);
More information about the Bf-blender-cvs
mailing list