I was stuck for a long time today on
PythonInterpreter‘s bug. Using gdb, I was able to trace down why it was crashing. Whenever a command was sent to Python using the C interface function
PyRun_SimpleString, it would in turn call
PyImport_AddModule( "__main__"). For some reason, this command would crash with the
"No such file or directory" error. Of course, this error should not happen.
__main__ (among others like
__built__) is supposed to be initialized with the
Py_Initialize() method. It was a weird error. I had made sure that Python was well initialized, but it hadn’t resolve anything.
Understanding that the nature of the problem was probably beyond the project’s interest (and my means…), I decided to use Blender’s Python functions directly (which is planned to be done at phase 2 of the project). I am surprised to see how quick the integration was: I used
add_text method to load the file into a
BPY_txt_do_python_Text method to execute the (fixed) script file,
BPY_Err_getLinenumber to display the error line number. The Python script is executed and stops because it doesn’t find the Freestyle module.
Next, I am going to compile the SWIG module wrapper and integrate it so that the Python interpreter can use it to call the Freestyle API functions.
The code was updated to properly handle
PythonInterpreter‘s initialization, following Freestyle original code.