Writing scene graphs fails for groups with field connections

Create issue
Issue #93 resolved
Thomas Moeller created an issue

Scenes with SoGroup or derived nodes are not always written correctly when applying SoWriteAction. This happens if a field is connected to a node in the scene graph that is traversed beforehand. The issue has initially been observed with node kits but it can also be reproduced easily with the following program that uses a couple separators.

#include <stdint.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/actions/SoWriteAction.h>
#include <Inventor/SoDB.h>

int main(int argc, char* argv[])
{
    // also output writeref for debugging
    putenv("COIN_DEBUG_WRITEREFS=1");

    SoDB::init();

    SoSeparator *root = new SoSeparator();
    root->ref();

    SoSeparator *sepA = new SoSeparator();
    sepA->setName("A");
    SoSeparator *sepB = new SoSeparator();
    sepB->setName("B");

    root->addChild(sepB);
    root->addChild(sepA);
    sepA->addChild(sepB);
    sepB->renderCaching.connectFrom(&sepA->renderCaching);

    SoOutput out;
    out.openFile("scene.iv");
    SoWriteAction writeAction(&out);
    writeAction.apply(root);

    root->unref();

    return 0;
}

In the produced output file the separator "B" has been defined twice and the writeref counts are incorrect (for which coin errors are reported).

#Inventor V2.1 ascii


Separator { # writeref: 1

  DEF B Separator { # writeref: 1

    renderCaching AUTO =
    DEF A Separator { # writeref: 2


      DEF B Separator { # writeref: 0

        renderCaching AUTO =
        USE A # writeref: 1
        . renderCaching

      }
    }    . renderCaching

  }
  DEF A+0 Separator { # writeref: 0


    USE B # writeref: -1

  }
}

Comments (3)

  1. Log in to comment