Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Image Viewer computation context doesn't seem to include the script's context #5654

Closed
ivanimanishi opened this issue Feb 1, 2024 · 0 comments

Comments

@ivanimanishi
Copy link
Member

Version: Gaffer 1.3.10.0-linux

Description

When including a script variable as input to a python expression that is driving a plug that is an ImagePlug, and having that in focus, so that the Viewer will try to draw the image, we can get errors because the script variable is not defined.

This can be worked around by having a fallback value that is valid.

Also, when the image is actually drawn, it seems that the context variable is set. It's only at the very beginning that it looks like we are computing it without providing a context that includes the script variables.

Finally, a similar setup that creates a 3d scene works fine (ex: driving a cube dimension via the same context variable).

Steps to reproduce

  1. Create a OSL constant shader, and drive one or more of its plugs with an expression trying to read the frameRange:start, with no fallback (so that you'd get None in case it's not defined).
  2. Try to view that node in the viewer.
  3. You should get an error complaining that you are trying to set None where a number is required.

I have provided an example graph below.

Debug log

Click to Expand

import Gaffer
import GafferOSL
import imath

Gaffer.Metadata.registerValue( parent, "serialiser:milestoneVersion", 1, persistent=False )
Gaffer.Metadata.registerValue( parent, "serialiser:majorVersion", 3, persistent=False )
Gaffer.Metadata.registerValue( parent, "serialiser:minorVersion", 10, persistent=False )
Gaffer.Metadata.registerValue( parent, "serialiser:patchVersion", 0, persistent=False )

__children = {}

__children["Constant"] = GafferOSL.OSLShader( "Constant" )
parent.addChild( __children["Constant"] )
__children["Constant"].loadShader( "Surface/Constant" )
__children["Constant"].addChild( Gaffer.V2fPlug( "__uiPosition", defaultValue = imath.V2f( 0, 0 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, ) )
__children["Expression"] = Gaffer.Expression( "Expression" )
parent.addChild( __children["Expression"] )
__children["Expression"]["__out"].addChild( Gaffer.Color3fPlug( "p0", direction = Gaffer.Plug.Direction.Out, defaultValue = imath.Color3f( 1, 1, 1 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, ) )
__children["Expression"].addChild( Gaffer.V2fPlug( "__uiPosition", defaultValue = imath.V2f( 0, 0 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, ) )
__children["Constant"]["parameters"]["Cs"].setInput( __children["Expression"]["__out"]["p0"] )
__children["Constant"]["__uiPosition"].setValue( imath.V2f( 4.9000001, 4.75 ) )
__children["Expression"]["__uiPosition"].setValue( imath.V2f( -4.09854746, 4.74918938 ) )
__children["Expression"]["__engine"].setValue( 'python' )
__children["Expression"]["__expression"].setValue( 'import imath\nc = context.get("frameRange:start")\nparent["__out"]["p0"] = imath.Color3f( c, c, c )' )


del __children


Results in the following error message:

ERROR : Emitting signal : Expression.__execute : Traceback (most recent call last):
  File "/software/apps/gaffer/1.3.10.0/cent7.x86_64/cortex/10.5/public/python/Gaffer/PythonExpressionEngine.py", line 89, in execute
    exec( self.__expression, executionDict, executionDict )
  File "<string>", line 3, in <module>
Boost.Python.ArgumentError: Python argument types in
    Color3f.__init__(Color3f, NoneType, NoneType, NoneType)
did not match C++ signature:
    __init__(boost::python::api::object, Imath_3_1::Vec3<int>)
    __init__(boost::python::api::object, Imath_3_1::Vec3<double>)
    __init__(boost::python::api::object, Imath_3_1::Vec3<float>)
    __init__(boost::python::api::object, Imath_3_1::Color3<unsigned char>)
    __init__(boost::python::api::object, Imath_3_1::Color3<int>)
    __init__(boost::python::api::object, Imath_3_1::Color3<float>)
    __init__(boost::python::api::object, int)
    __init__(boost::python::api::object, float)
    __init__(boost::python::api::object, int, int, int)
    __init__(boost::python::api::object, float, float, float)
    __init__(boost::python::api::object, boost::python::list)
    __init__(boost::python::api::object, boost::python::tuple)
    __init__(boost::python::api::object)
    __init__(_object*, Imath_3_1::Color3<float>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant