WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-23-2011, 09:09 PM
dcnieho dcnieho is offline
Member
 
Join Date: Feb 2011
Posts: 59
Hi Farshizzo,

Thank you for all the detailed information! I still have some questions though:

Quote:
Originally Posted by farshizzo View Post
No, but you can internally save a reference to them. This is what most of the built-in plugins do. For example, the extension class can keep a list of sensor objects created by it:
Code:
std::list< viz::ref_ptr< MySensor > > m_sensors;
Is this supposed to be
Code:
std::list< osg::ref_ptr< MySensor > > m_sensors;
instead? I don't seem to have a viz::ref_ptr (but do have a viz::Referenced*). In any case, things seem to work fine with osg::ref_ptr

Quote:
Originally Posted by farshizzo View Post
The new interface allows you to return arbitrary Python objects from the command method, so you can return anything you wish to signal an error. If you want to raise a Python exception from your plugin, then you can use the Python PyErr_SetString function to raise an exception.
I am trying the Python PyErr_SetString method and I'm having some trouble with it. If I do a normal (non-debug) run and raise/set an error in my plugin, an error occurs on the next command call in the python node class that interfaces with the C++ node instance:
Code:
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "C:\dat\C\projects\Vizard dll\testCustomNode.py", line 58, in <module>
    stim.setStimSpec('GDcl')
  File "DNstimuli.py", line 45, in setStimSpec
    self.command(1,stimSpec)
  File "C:\Program Files\WorldViz\Vizard4\python\viz.py", line 6837, in command
    return _ipcSend(_VIZ_CMDEXTNODE,self.id,command,mesg,x,y,z,w)
TypeError: command must be an int
The line self.command(1,stimSpec) is the first command I sent to the node after the command in which the exception was raised (which created no output or anything when raised), there can be any amount of code in between these two calls.

If setup a debug breakpoint on this first call after the raised exception (self.command(1,stimSpec)), and try to step into it, i get this output:
Code:
C:\Program Files\WorldViz\Vizard4\python\vizbdb.py:410: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
  if id in ids:
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "C:\dat\C\projects\Vizard dll\testCustomNode.py", line 58, in <module>
    stim.setStimSpec('GDcl')
  File "DNstimuli.py", line 45, in setStimSpec
    self.command(1,stimSpec)
  File "DNstimuli.py", line 45, in setStimSpec
    self.command(1,stimSpec)
  File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 254, in trace_debug
    self.wait_for_input(frame,None)
  File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 436, in wait_for_input
    id,data = self.wait_for_message(_INPUT_MESSAGES)
  File "C:\Program Files\WorldViz\Vizard4\python\vizbdb.py", line 410, in wait_for_message
    if id in ids:
RuntimeError: testing
The good part here is that "RuntimeError: testing" is what I am throwing from the C++ code (PyErr_SetString(PyExc_RuntimeError, "testing");)

Other things I tried:
- doing data.set( PYTHON_RETURN_OBJECT, PYTHON_INT(-1)); or data.set(PYTHON_RETURN_OBJECT, NULL); after the call to PyErr_SetString did not help (inspired by some reading of how error states should be communicated from Python).
- try/except around the call where the exception is raised. This didn't do anything, as expected when the exception goes unnoticed.

What am I missing? Thanks for your help!
Reply With Quote
  #2  
Old 05-24-2011, 08:46 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Quote:
Originally Posted by dcnieho View Post
Is this supposed to be
Code:
std::list< osg::ref_ptr< MySensor > > m_sensors;
instead? I don't seem to have a viz::ref_ptr (but do have a viz::Referenced*). In any case, things seem to work fine with osg::ref_ptr
The viz::ref_ptr usage was intentional. You need to #include <viz/ref_ptr> which should come with the SDK.

Quote:
Originally Posted by dcnieho View Post
Other things I tried:
- doing data.set( PYTHON_RETURN_OBJECT, PYTHON_INT(-1)); or data.set(PYTHON_RETURN_OBJECT, NULL); after the call to PyErr_SetString did not help (inspired by some reading of how error states should be communicated from Python).
- try/except around the call where the exception is raised. This didn't do anything, as expected when the exception goes unnoticed.

What am I missing? Thanks for your help!
You should have to set NULL as the return object. However, I just noticed that Vizard is eating up the exception if NULL is returned by the plugin. We'll need to fix this for the next release. In the meantime I would just raise the exception from the Python wrapper method.
Reply With Quote
  #3  
Old 07-12-2012, 07:17 AM
dcnieho dcnieho is offline
Member
 
Join Date: Feb 2011
Posts: 59
Quote:
Originally Posted by farshizzo View Post
The viz::ref_ptr usage was intentional. You need to #include <viz/ref_ptr> which should come with the SDK.

You should have to set NULL as the return object. However, I just noticed that Vizard is eating up the exception if NULL is returned by the plugin. We'll need to fix this for the next release. In the meantime I would just raise the exception from the Python wrapper method.
Sorry to dig up an old thread, but i am just testing this again with the newest Vizard 4 and SDK (both freshly downloaded today).

When try to send an exception from my python plugin as follows
Code:
PyErr_SetString(PyExc_RuntimeError, "errorstring");
data.set( PYTHON_RETURN_OBJECT, NULL);


I always get a TypeError instead of the exception i'm trying to communicate. The stacktrace always ends like this:
Code:
  File "C:\Program Files (x86)\WorldViz\Vizard4\python\viz.py", line 7381, in command
    return _ipcSend(_VIZ_CMDEXTNODE,self.id,command,mesg,x,y,z,w)
TypeError: command must be an int
The next call above that is me calling the C++ code from the extension node, e.g. self.command(1,stimSpec) (my node derives from viz.VizExtensionNode)

I'm not sure what this typeerror is referring to, as my command is correct, it works without error when not trying to return an exception.

Am I doing something wrong?

Best and thanks,
Dee
Reply With Quote
  #4  
Old 07-12-2012, 11:30 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Can you post the full traceback? It looks like you are using passing an invalid parameter to the command method. As the traceback says, the first argument must be an int, and you are most likely passing some other type.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:44 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC