gerwindehaan / osgswig

Python bindings for OpenSceneGraph (auto-export from code.google.com/p/osgswig)
Other
1 stars 1 forks source link

Uniform::set typemaps don't work anymore #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
osg.Uniform.set used to work like using its typemaps (so you can feed it 
ducktyped floats, ints, etc.) but somewhere between changesets 80fd1ee3df62 and 
9eeabfc8d7b1 this stopped working. Seeing how the SWIG code regarding 
Uniform::set hasn't changed, I don't know what's causing it.

To reproduce:

1. ipython
2. import osg
3. u = osg.Uniform()
4. u.set(1.0)

What you get:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)

/data/Workspace/<ipython console> in <module>()

/data/Workspace/osgswig/osgswig-2.9.11/build/r64_lucid/lib/python/osgswig-2.9.11
/osg.pyc in set(self, *args)
  33988             unsigned int i3) -> bool
  33989         """
> 33990         return _osg.Uniform_set(self, *args)
  33991
  33992     def set_bool2(self, *args):

NotImplementedError: Wrong number of arguments for overloaded function 
'Uniform_set'.
  Possible C/C++ prototypes are:
    set(osg::Uniform *,unsigned int)
    set(osg::Uniform *,unsigned int,unsigned int)
    set(osg::Uniform *,unsigned int,unsigned int,unsigned int)
    set(osg::Uniform *,unsigned int,unsigned int,unsigned int,unsigned int)

To work around:

There are (older?) osg.Uniform.set_<typename> methods you can use instead. For 
example. u.set_float(1.0).

Original issue reported on code.google.com by yunarai...@gmail.com on 25 Mar 2011 at 6:46

GoogleCodeExporter commented 9 years ago
Hi,

The unsigned int are currently not renamed, this type is missing from the 
rename list. If these would be renamed there will be no set function in python, 
u.set(1.0) will cause an AttributeError. and u.set_float must then be used.

If the renames would simply be removed, swig will take care of the overloading 
for set, however get will then have many problems like this:

1>C:\tmp\win64_local\OpenSceneGraph-2.8.3\include\osg\Uniform(345) : Warning 
509: Overloaded method osg::Uniform::get(int &) const effectively ignored,
1>C:\tmp\win64_local\OpenSceneGraph-2.8.3\include\osg\Uniform(344) : Warning 
509: as it is shadowed by osg::Uniform::get(float &) const.

a solution could be renaming only the get functions (and add the get unsigned 
int renames).

don't know what caused the 'don't work anymore'. Could be a change in the osg 
version or in the swig version.

see:
http://www.swig.org/Doc2.0/Python.html#Python_nn23

René

Original comment by Megamill...@gmail.com on 25 Mar 2011 at 9:25

GoogleCodeExporter commented 9 years ago
It can't be a change in the OSG version, because it worked with 2.8.3 before 
the aforementioned changesets.

I should mention that when I said "typemaps" in the problem description and 
title, I mistakingly assumed the typemaps for Uniform in osg.i were for 
Uniform.set. Naturally they are for Uniform.get. Perhaps these typemaps are 
also what's causing the shadowing problems with Uniform.get, since they 
effectively transform all differently typed get methods to just get().

I personally have no problem with using the "set_<typename>" renames, BTW. When 
I read your explanation, it seems very odd that it used to work at all!

Original comment by yunarai...@gmail.com on 26 Mar 2011 at 11:55

GoogleCodeExporter commented 9 years ago
Uniform.getElement and uniform.setElement suffer from the same issue, BTW. And 
the typemaps for Uniform near the bottom of osg.i actually don't do anything 
anymore, so if the renames end up being the selected solution, the "apply"s 
around line 1100 can be removed, I think.

Original comment by yunarai...@gmail.com on 27 Mar 2011 at 12:10

GoogleCodeExporter commented 9 years ago
I think I know why the behaviour changed. In revision f193ce9245d7 the set 
renames were apparently added. I probably had an older and/or branched revision 
built myself, although I seem to remember seeing the set renames in osg.i.

Original comment by yunarai...@gmail.com on 28 Mar 2011 at 1:28