Complemento: open_mainfile () siempre conduce a una falla de segmentación

Aug 23 2020

He estado luchando por hacer que bpy.ops.wm.open_mainfile(filepath=PATH)funcione correctamente dentro de un complemento.

No importa lo que haga y dónde lo ponga, siempre obtengo:

segmentation fault  /Applications/Blender.app/Contents/MacOS/Blender

Por ahora lo estoy probando así:

  1. Estoy agregando un controlador para detectar cuándo se abre un archivo

     bpy.app.handlers.load_post.append(load_post)
    
  2. En este controlador, estoy configurando un temporizador para abrir un nuevo archivo después de 5 segundos

     def load_post(ok,no):
         global t
         t = Timer(5.0, openNew)
         t.start()
    
  3. Entonces el openNewse define así

     def hello():
         t.cancel()
         bpy.ops.wm.open_mainfile(filepath="/correct/file/path/test.blend")
    

¿Por qué lo estoy probando así? Porque estoy tratando de crear un complemento que abra un archivo, haga algo en este archivo, lo guarde y luego abra el siguiente archivo. Timer es una simulación de esto.

Aquí está el registro de fallos.

# backtrace
0   Blender                             0x0000000107437387 BLI_system_backtrace + 55
1   Blender                             0x0000000100fe8ef8 sig_handle_crash + 392
2   libsystem_platform.dylib            0x00007fff693415fd _sigtramp + 29
3   ???                                 0x0000000000000000 0x0 + 0
4   Blender                             0x0000000101663bb7 Scene_statistics_call + 39
5   Blender                             0x0000000101556fc2 RNA_function_call + 18
6   Blender                             0x00000001016e67a4 pyrna_func_call + 2004
7   Blender                             0x0000000105e89faf _PyObject_FastCallKeywords + 575
8   Blender                             0x0000000105f5f485 call_function + 773
9   Blender                             0x0000000105f5beee _PyEval_EvalFrameDefault + 27262
10  Blender                             0x0000000105e8a66d function_code_fastcall + 237
11  Blender                             0x00000001016e8221 bpy_class_call + 961
12  Blender                             0x00000001016973e3 header_draw + 115
13  Blender                             0x00000001017000a4 ED_region_header_layout + 404
14  Blender                             0x000000010132b2ff wm_draw_update + 1631
15  Blender                             0x0000000101329040 WM_main + 48
16  Blender                             0x0000000100fe5621 main + 929
17  libdyld.dylib                       0x00007fff69148cc9 start + 1

PD: si ejecuto este comando exacto en el área de secuencias de comandos del archivo Blend, y no desde un complemento, funciona de maravilla.

Respuestas

1 CarlosC Aug 24 2020 at 00:47

La creación de subprocesos no es compatible con Blender.

Así que lo cambié a:

import bpy
def test():
    bpy.ops.wm.open_mainfile(filepath=bpy.data.filepath)
    return -1.0
bpy.app.timers.register(test)

Pero esto tampoco estaba funcionando. La versión 2.91.0 Alpha ya tiene un compromiso para corregir este error.

Puedes consultar las notas comprometidas aquí:https://developer.blender.org/T80028