Putting collide(obj) inside a for loop consistently crashes Blender

Hey folks,

Uppon running this function, Blender crashes after about half a minute.

def colCheck(own,objList):
    isCol = False
    for other in objList:
        col = own.collide(other)
        if col[0]:
            isCol = True
            break
    return isCol

And if I don’t check for colliision or do the check outside the loop it works just fine. So I’m a bit confused. I just need to know whether I’m colliding or not with any of a few nearby objects.
Any ideas on another way to go around it?

and if you remove the break, then what happens?

Aye, I tried that; doesn’t seem to make a difference. No matter how I phrase the function, for as long as I check for collision inside the loop, I get the same crash.

What I’m thinking is, it might be something with the build I’m using, as I can’t find anything else within my code that reproduces the crash. So I might have to report it as a bug/help patch it. All I really need to think of now is a workaround to use in the meantime.

What is the “collide” method that you’re calling? I’m not familiar with there being a collide method on KX_GameObjects. Did you make the method yourself?

Try to print if other is invalid or not. Maybe one of the objects is disposed, dunno.

@Mobious UPBGE adds this to KX_GameObjects.

^I checked, but no luck. Everything seems to be fine – all the right objects are in the list and they’re all game object instances. Troubling. I’m okay with crashes when they’re my fault but this one seems to be beyond me.

Anyway, I came up with an alternative which might not be quite as precise as actual collision detection but works well to detect the kind of proximity I need. I’ll put it here in case someone else runs into the same issue, could come in handy.

def colCheck(own,objList):
    isCol = False
    for other in objList:
        distance = own.getDistanceTo(other)
        colRange = (own.cullingBox.radius+other.cullingBox.radius)/2.666
        isCol = distance < colRange
        if isCol:
            break
    return isCol

EDIT: effy math.

could it be a recursive loop?

That’s a possibility, maybe collide isn’t meant to be called with frequency. But I haven’t read any notes on the API saying so, and that’s usually the first place where you learn a method is expensive. Guess I’ll have to do some testing and find out.