Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
H3D.org Feeds
H3D.org Forum Index
   Programming Issues
     Problem with nested prototypes in H3D trunk (r1943)
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
karlsvec
Posted on: 2012/7/25 2:01
Quite a regular
Joined: 2008/7/1
From:
Posts: 41
Problem with nested prototypes in H3D trunk (r1943)
Hello,

In the latest H3D trunk, I am unable to load a prototype that is a composition of other ProtoInstances.

Example:

ProtoOne.x3d
<X3D>
    <
Scene>
        <
ProtoDeclare name='ProtoOne'>
            <
ProtoInterface>
                <
field name='radius' type='SFFloat' accessType='inputOutput' value='0.5'/>
                <
field name='diffuseColor' type='SFColor' accessType='inputOutput' value='1 0 0'/>
            </
ProtoInterface>
            <
ProtoBody>
                <
Shape>
                    <
Appearance>
                        <
Material>
                            <
IS>
                                <
connect nodeField='diffuseColor' protoField='diffuseColor'/>
                            </
IS>
                        </
Material>
                    </
Appearance>
                    <
Sphere>
                        <
IS>
                            <
connect nodeField='radius' protoField='radius'/>
                        </
IS>
                    </
Sphere>
                </
Shape>
            </
ProtoBody>
        </
ProtoDeclare>
    </
Scene>
</
X3D>


ProtoTwo.x3d
<X3D>
    <
Scene>
        <
ProtoDeclare name='ProtoTwo'>
            <
ProtoInterface>
                <
field name='size' type='SFVec3f' accessType='inputOutput' value='0.2 0.2 0.2'/>
                <
field name='diffuseColor' type='SFColor' accessType='inputOutput' value='1 0 0'/>
            </
ProtoInterface>
            <
ProtoBody>
                <
Shape>
                    <
Appearance>
                        <
Material>
                            <
IS>
                                <
connect nodeField='diffuseColor' protoField='diffuseColor'/>
                            </
IS>
                        </
Material>
                    </
Appearance>
                    <
Box>
                        <
IS>
                            <
connect nodeField='size' protoField='size'/>
                        </
IS>
                    </
Box>
                </
Shape>
            </
ProtoBody>
        </
ProtoDeclare>
    </
Scene>
</
X3D>


WrapperProto.x3d (a composition of ProtoOne and ProtoTwo)
<X3D>
    <
Scene>
        <
ExternProtoDeclare name='ProtoOne' url='ProtoOne.x3d#ProtoOne'>
            <
field name='radius' type='SFFloat' accessType='inputOutput'/>
            <
field name='diffuseColor' type='SFColor' accessType='inputOutput'/>
        </
ExternProtoDeclare>
        <
ExternProtoDeclare name='ProtoTwo' url='ProtoTwo.x3d#ProtoTwo'>
            <
field name='size' type='SFVec3f' accessType='inputOutput'/>
            <
field name='diffuseColor' type='SFColor' accessType='inputOutput'/>
        </
ExternProtoDeclare>
        <
ProtoDeclare name='WrapperProto'>
            <
ProtoInterface>
                <
field name='rightTranslation' type='SFVec3f' accessType='inputOutput' value='1 0 0'/>
                <
field name='leftTranslation' type='SFVec3f' accessType='inputOutput' value='-1 0 0'/>
            </
ProtoInterface>
            <
ProtoBody>
                <
Group>
                    <
Transform>
                        <
IS>
                            <
connect nodeField='translation' protoField='rightTranslation'/>
                        </
IS>
                        <
ProtoInstance name='ProtoOne'/>
                    </
Transform>
                    <
Transform>
                        <
IS>
                            <
connect nodeField='translation' protoField='leftTranslation'/>
                        </
IS>
                        <
ProtoInstance name='ProtoTwo'/>
                    </
Transform>
                </
Group>
            </
ProtoBody>
        </
ProtoDeclare>
    </
Scene>
</
X3D>


The test scene:

test_WrapperProto.x3d
<X3D>
    <
Scene>
        <
ExternProtoDeclare name='WrapperProto' url='WrapperProto.x3d#WrapperProto'>
            <
field name='rightTranslation' type='SFVec3f' accessType='inputOutput'/>
            <
field name='leftTranslation' type='SFVec3f' accessType='inputOutput'/>
        </
ExternProtoDeclare>
        <
Group>
            <
ProtoInstance name='WrapperProto'/>
        </
Group>
    </
Scene>
</
X3D>


When I load the test scene in H3DLoad, I get the following error output:
Loading c:/Users/Karl Svec/Desktop/test_WrapperProto.x3d
Warning
Could not find PROTO declaration for "ProtoOne" instance (<string input>, line 7)
WarningCould not find PROTO declaration for "ProtoTwo" instance (<string input>, line 15)
OpenGL error before H3DDisplayListObject::DisplayList::callList() Error"invalid enumerant" when rendering parent of Unnamed Group.displayList


I spent some time stepping through things with GDB. I set a breakpoint at line 887 in X3DSAX2Handlers.cpp, within the definition of X3DSAX2Handlers::protoEndElement():

if( localname_string == "ProtoDeclare" ) {
    if( 
proto_declaration ) {
      
proto_declarations->push_backproto_declaration );
      if( !
proto_declarations->getFirstProtoDeclaration() ) {
        
proto_declarations->setFirstProtoDeclarationproto_declaration );
      }
      
proto_declaration NULL;
    }
  } else if( 
localname_string == "ExternProtoDeclare" ) {
    if( 
proto_declaration ) {
      
proto_declarations->push_backproto_declaration );
      
proto_declaration NULL// <--- breakpoint here


I can step through the program and see the proto_declarations list being built up with the declarations from the ExternProtoDeclares.

However, when I set another breakpoint at line 935 of X3DSAX2Handlers.cpp, within the definition of X3DSAX2Handlers::handleProtoInstanceElement(), when it comes time to actually instantiate the ProtoInstances, the declarations are no longer in the proto_declarations list.

X3DPrototypeInstanceX3DSAX2Handlers::handleProtoInstanceElement( const Attributes &attrs ) {
  const 
XMLCh *name attrs.getValuegname );
  if( 
name ) {
    
string s_name toStringname );
    
ProtoDeclaration *proto 
      
proto_declarations->getProtoDeclarations_name );
    if( 
proto ) return proto->newProtoInstance(); // <--- breakpoint here
    
else {
      
Console(3) << "Warning: Could not find PROTO declaration for "" << s_name  
           << "" instance (" 
<< toStringlocator->getSystemId() )
           << 
", line " << locator->getLineNumber() << ")" << endl;
    }


Is it possible that the proto_declarations list is being destroyed prematurely, rather than being carried through to the actual ProtoInstance instantiations?

I'd appreciate any help on the matter.

Thanks,

- Karl
karlsvec
Posted on: 2012/7/28 0:47
Quite a regular
Joined: 2008/7/1
From:
Posts: 41
Re: Problem with nested prototypes in H3D trunk (r1943)
I posted a work-in-progress patch that addresses this issue. See http://www.h3dapi.org/modules/newbb/v ... php?topic_id=1853&forum=4.
karlsvec
Posted on: 2012/8/15 20:20
Quite a regular
Joined: 2008/7/1
From:
Posts: 41
Re: Problem with nested prototypes in H3D trunk (r1943)
Bumping this thread. Hopefully it will draw the attention of the SenseGraphics devs.
karlsvec
Posted on: 2012/8/23 22:18
Quite a regular
Joined: 2008/7/1
From:
Posts: 41
Re: Problem with nested prototypes in H3D trunk (r1943)
I tested these example scenes with the latest Xj3D 2.0 pre-release, and they work as I expected (albeit with some modifications required to make them X3D-compliant).

So, this is definitely a bug in H3D, related to the bug involving default field values in prototypes described in this thread.

- Karl
Markus
Posted on: 2012/10/11 15:17
Webmaster
Joined: 2006/3/27
From: SenseGraphics
Posts: 1902
Re: Problem with nested prototypes in H3D trunk (r1943)
This issue, and the other thread (http://www.h3dapi.org/modules/newbb/v ... php?topic_id=1853&forum=4) connected to bug report 0000296 should be fixed in H3DAPI trunk revision 2010.

If you have some other/a bigger example than the ones provided in these threads please update H3DAPI and test that the fix works.
karlsvec
Posted on: 2012/10/18 0:45
Quite a regular
Joined: 2008/7/1
From:
Posts: 41
Re: Problem with nested prototypes in H3D trunk (r1943)
I have tested a handful of my more complex prototypes (that use nested ProtoInstances) with the latest H3DAPI trunk, and they are all working fine.

Thanks for getting this issue resolved quickly!
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 



(C) 2012 SenseGraphics AB    ---    Powered by XOOPS