Page MenuHome

bvhtree.fromObject - error ( returned NULL without setting an error) in blender 2.8
Closed, ResolvedPublic


x = bvhtree.BVHTree.FromObject(C.active_object, C.scene)
Is broken in blender 2.8 builds for some time now. I also tested on latest build from 4 December.

Error message:
raceback (most recent call last):

File "<blender_console>", line 1, in <module>

SystemError: <built-in method FromObject of type object at 0x0444CA30> returned NULL without setting an error

Event Timeline

Bastien Montagne (mont29) changed the task status from Unknown Status to Resolved.Dec 5 2018, 11:29 AM
Bastien Montagne (mont29) lowered the priority of this task from 90 to 50.

For the record, the API changed, see e7c3f7ba6f1385a2138862de8568e571fa97b5b4.

Jose Conseco (joseconseco) changed the task status from Resolved to Unknown Status.Dec 8 2018, 6:19 PM

Thanks for the fix. The operation bvhtree .fromObject now works when executed once. But it crashes on second run of operation each time:
Steps to reproduce:
run in console:

from mathutils.bvhtree import BVHTree
BVHTree.FromObject(C.active_object, C.depsgraph) 
BVHTree.FromObject(C.active_object, C.depsgraph)  #it will crash here (no error)

In addon I developed I have operator with some F6 props, and if I edit any F6 operator props, BVHTree.FromObject will crash blender. Simple operator example (run it 2x to to crash blender):

import bpy
from mathutils.bvhtree import BVHTree

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def execute(self, context):
        sourceSurface_BVHT = BVHTree.FromObject(context.active_object, context.depsgraph) #crash on second run from F6 props
        print('Crash on second run')
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

It actually crashes immediatelly with:
BLI_assert failed: //source/blender/blenkernel/intern/DerivedMesh.c:2192, mesh_get_eval_final(), at 'ob->id.tag & LIB_TAG_COPIED_ON_WRITE'

For the records, I can "fix" the initial crash with P872, however when I call it the second time I indeed get a crash:

SUMMARY: AddressSanitizer: heap-use-after-free //source/blender/blenkernel/intern/DerivedMesh.c:2208 in mesh_get_eval_final
Full backtrace: P871

@Sergey Sharybin (sergey) suggestions?

Think your assert is a side effect. Surely, should be fixed, but don't think it will crash.

The P872 is wrong. Is ok to mock around with evaluated objects which you control and own (as in the baking), but you must not do such trickery for objects which are only "leased" to you ;) Doing such stuff will confuse regular evaluation routines.

The fact that crash is only happening on redo makes me believe that it's same type of errors where operator wants to know evaluated state of the scene an unless special flag is set for an operator, dependency graph is not guaranteed to be evaluated.

Issue is actually dead simple: C_BVHTree_FromObject() unconditionally frees its mesh, when bvh_get_mesh() actually may return direct data from evaluated object, not always creating its own mesh...

As for the asserts, one just have to pass eval object to mesh_get_eval_xxx() functions, not orig one.

great! works like a charm now :-) (tested on linux 64bit)