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

node_Viewer.py / Viewer draw #66

Closed
zeffii opened this issue Apr 10, 2014 · 11 comments
Closed

node_Viewer.py / Viewer draw #66

zeffii opened this issue Apr 10, 2014 · 11 comments

Comments

@zeffii
Copy link
Collaborator

zeffii commented Apr 10, 2014

fresh blend file, add node_Viewer.py

Traceback (most recent call last):
  File "C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\node_s.py", lin
e 97, in update
    speedUpdate(tree_name = self.name)
  File "C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\util.py", line
1055, in speedUpdate
    do_update(list_nodes4update[tree_name],bpy.data.node_groups[tree_name].nodes)
  File "C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\util.py", line
1020, in do_update
    nods[nod_name].update()
  File "C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\node_Viewer.py"
, line 147, in update
    if self.activate and (self.inputs['vertices'].links or self.inputs['matrix'].links):
KeyError: 'bpy_prop_collection[key]: key "matrix" not found'

location: C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\node_Viewer.p
y:121

location: C:\blender_trunk\2.70\scripts\addons\sverchok-master\..\sverchok-master\node_Viewer.p
y:121

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 10, 2014

I don't understand this code well enough to make a fix yet.

@ly29
Copy link
Collaborator

ly29 commented Apr 10, 2014

This is in the category of non important errors, still an error.
What happens is that every time you create a socket by calling self.inputs.new() in def init(self, context)
the update function is called.
To fix add check that the 'matrix' key is in self.inputs, like:
if 'Float' in self.inputs and self.inputs['Float'].links:

The update function is furthermore called on every editor change...
Long term we should change sverchok to handle, this and the pynodes interface is also evolving.

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 10, 2014

the update function is quite difficult to read.

@nortikin
Copy link
Owner

i didn't even looket to update function, to my shame. This difficult part for me

@ly29
Copy link
Collaborator

ly29 commented Apr 11, 2014

Some notes on the general problem of the update function:

Note that this error is due to general problem with how blender calls the update function on editor changes, also before the init functon finishes. So update should be able to handle a state where, for example, only half the sockets that are created in init are created...

Once the node is created update is called on every node update, either from the general update function in node_s or from the updateNode function that we attach to changing number fields for example.

In conclusion, this should be fixed so the update function verifies that the socket exist before trying to access it. However this error is non critical in the way that once the node is created it does not happen again and nothing actually breakes because of this error.

If you want some further pointers on how the update system works I can try explain it better.

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 11, 2014

thank you nortikin and ly29 getting sverchok this far, and acknowledging + explaining the scenario.of the error. It's good to document these things concretely..I've noticed other non critical errors cascade from them.

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 11, 2014

can't we stick a

if not all([x in self.inputs for x in ['vertices', 'edg_pol', 'matrix']]):
      return

in the update, before checking the link presence. This way also the various separate checks on self.inputs for vertices edg_pol and matrix can be skipped.

like snippet:

    def update(self):
        global cache_viewer_baker
        cache_viewer_baker[self.name+'v'] = []
        cache_viewer_baker[self.name+'ep'] = []
        cache_viewer_baker[self.name+'m'] = []

        if not all([x in self.inputs for x in ['vertices', 'edg_pol', 'matrix']]):
            return

        if self.activate and (self.inputs['vertices'].links or self.inputs['matrix'].links):
            callback_disable(self.name)

            if self.inputs['vertices'].links and \
                type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:

                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                cache_viewer_baker[self.name+'v'] = dataCorrect(propv)
            else:
                cache_viewer_baker[self.name+'v'] = []

            if self.inputs['edg_pol'].links and \
                type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                cache_viewer_baker[self.name+'ep'] = dataCorrect(prope)
                #print (prope)
            else:
                cache_viewer_baker[self.name+'ep'] = []

            if self.inputs['matrix'].links and \
               type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                    propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                    cache_viewer_baker[self.name+'m'] = dataCorrect(propm)
            else:
                cache_viewer_baker[self.name+'m'] = []

   (.....)

@ly29
Copy link
Collaborator

ly29 commented Apr 11, 2014

Yes something like that would work.

11 apr 2014 kl. 12:01 skrev "Dealga McArdle" notifications@github.com:

can't we stick a

if not all([x in self.inputs for x in ['vertices', 'edg_pol', 'matrix']]):
return
in the update, before checking the link presence. This way also the various separate checks on self.inputs for vertices edg_pol and matrix can be skipped.

like snippet:

def update(self):
    global cache_viewer_baker
    cache_viewer_baker[self.name+'v'] = []
    cache_viewer_baker[self.name+'ep'] = []
    cache_viewer_baker[self.name+'m'] = []

    if not all([x in self.inputs for x in ['vertices', 'edg_pol', 'matrix']]):
        return

    if self.activate and (self.inputs['vertices'].links or self.inputs['matrix'].links):
        callback_disable(self.name)

        if self.inputs['vertices'].links and \
            type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:

            propv = SvGetSocketAnyType(self, self.inputs['vertices'])
            cache_viewer_baker[self.name+'v'] = dataCorrect(propv)
        else:
            cache_viewer_baker[self.name+'v'] = []

        if self.inputs['edg_pol'].links and \
            type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
            prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
            cache_viewer_baker[self.name+'ep'] = dataCorrect(prope)
            #print (prope)
        else:
            cache_viewer_baker[self.name+'ep'] = []

        if self.inputs['matrix'].links and \
           type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                cache_viewer_baker[self.name+'m'] = dataCorrect(propm)
        else:
            cache_viewer_baker[self.name+'m'] = []

(.....)

Reply to this email directly or view it on GitHub.

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 11, 2014

@ly29
Copy link
Collaborator

ly29 commented Apr 11, 2014

Yes it should work fine here.
A potential problem with this as a general solution is that socket.name is not a guaranteed to be unique.

@zeffii
Copy link
Collaborator Author

zeffii commented Apr 11, 2014

OK, i'll stick to smaller changes for the time being. Thanks for the review, I understand the reservation.

@zeffii zeffii closed this as completed Apr 11, 2014
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

3 participants