在setDependentsDirty()期间,脏插头仍具有旧值 [英] Dirtied plug still has the old value during setDependentsDirty()

查看:91
本文介绍了在setDependentsDirty()期间,脏插头仍具有旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我弄脏输入插头(例如mFileAttr)时,会正确调用setDependentsDirty(),但是fileName插头的值仍然是旧值!我只看到它通过compute()后就得到更新. setDependentsDirty()函数中的新值确实是由插件值更新触发的,我该如何访问?

When I dirty an input plug for example mFileAttr, the setDependentsDirty() gets properly invoked, but the value of fileName plug is still the old value! I only see it getting updated once it goes through compute(). How can I access the new value in setDependentsDirty() function since it's indeed triggered by the plug value update?

MStatus FNode::setDependentsDirty(const MPlug& plug, MPlugArray& plugArray) {
    if (plug == mFileAttr)
    { 
        MPlug fileNamePlug(thisMObject(), plug);
        MString fileName = fileNamePlug.asString();
    }
    return MPxNode::setDependentsDirty(plug, plugArray); }

为了澄清起见,读取插头值本身plug.asString()仍然保留旧值.

Just to clarify, reading plug value itself, plug.asString(), it still holds the old value.

推荐答案

如果您仔细阅读doc,您将看到为什么没有获得更新后的值

If you take close look in doc you will see why you are not getting the updated value

重要说明:由于setdirentsDirty()方法是在脏传播期间调用的,因此必须小心不要在例程中执行任何依赖图计算.相反,如果您想知道插头的值,请使用MDataBlock :: outputValue(),因为它不会导致计算(因此不会递归).通常,用户将实现的大多数{setDependentsDirty()}方法应该只涉及固定关系.插头值,请使用{MDataBlock :: outputValue()}注意警告,并使用包含您知道在不正确传播开始之前最新的值的插头. "

"IMPORTANT NOTE: since the setDependentsDirty() method is called during dirty propagation, you must be careful not to perform any dependency graph computations from within the routine. Instead, if you want to know the value of a plug, use MDataBlock::outputValue() because it will not result in computation (and thus recursion). In general, the majority of {setDependentsDirty()} methods which users will implement should involve only fixed relationships. In the rare occurence where you need to look at plug values, please heed the warning with {MDataBlock::outputValue()} and use plugs which contain values which you know to be up to date prior to the start of dirty propagation. "

这篇关于在setDependentsDirty()期间,脏插头仍具有旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆