JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
545 stars 74 forks source link

accessing bpy.context.object crashes Blender #86

Closed risa2000 closed 1 year ago

risa2000 commented 3 years ago

I am facing a strange behavior when debugging a Python script (i.e. not and add-on) which uses the following pattern:

bpy.ops.mesh.primitive_cylinder_add(vertices=8, radius=CYLINDER_RADIUS, depth=CYLINDER_HEIGHT, location=location, rotation=rotation)
obj = bpy.context.object
obj.name = name

i.e. it creates a primitive mesh (and corresponding object) and then tries to rename the object. This works when I run the script from command line using --python command line parameter.

When I run it in the debugger it however crashes at the obj = bpy.context.object with:

Error   : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF713D495D4
Module  : blender.exe
Thread  : 00001fc8

I found an issue reported here #63 which seems related except in my case, it does not crash at bpy.ops.mesh.primitive_cylinder_add call but at bpy.context.object and only when running in debugger.

The only workaround I found is instead of using bpy.context.object I am simply searching for Cylinder named object in bpy.data.objects and then renaming it there. But this seems like wasting performance. Is there a way to fix it, or what would be the best practice to handle a pattern like this (so it runs in both the command line and the debugger as well)?

CGArtPython commented 1 year ago

I am closing this issue. This was resolved with this commit https://github.com/JacquesLucke/blender_vscode/commit/621e275d9000e571f4b4d10cbde7abdd1cf15e0a