Maya Reload Reference With Callback (HARD CRASH)

Hey guys,

I’m getting a really bad crash when I try to reload ANY reference inside of a Maya callback.
(Using Maya 2014 SP3)

Example


import pymel.core as pymel
import maya.OpenMaya as OpenMaya

FILE_PATH = "ADD MA PATH"

def create_then_reload_reference( *args):
	reference_node = pymel.createReference(FILE_PATH, namespace = '' )
	reference_node.load()
	
OpenMaya.MSceneMessage.addCallback( OpenMaya.MSceneMessage.kAfterNew, create_then_reload_reference )

The strange thing is that this proc works fine when you run create_then_reload_reference() manually.
If anyone has any idea on why Maya crashes every time please let me know!

Thanks,
-Nick

have you tried doing this inside a maya.utils.executedeferred()?

Thanks Theodox!!!

This seems to work out perfectly!


from pymel.all import *
import maya.OpenMaya as OpenMaya

REFERENCE_PATH = ""

def reload_reference():
	reference_node = createReference(REFERENCE_PATH, namespace = '' )
	reference_node.load()

def update_scene(*args):
	mayautils.executeDeferred( reload_reference )
	
	
OpenMaya.MSceneMessage.addCallback( OpenMaya.MSceneMessage.kAfterNew, update_scene )

A lucky guess. Hard crashes in python are almost always caused by cross-threaded access :slight_smile: