Results 1 to 3 of 3

Thread: Usage of createElement()

  1. #1

    Usage of createElement()


    I'm a bit confused about how to use the createElement() - methods in the DOM.

    Please correct me, if I'm wrong, but I thought, you can create an element via this method, manipulate it, and then place it somewhere else (maybe even in another document).

    Anyhow, this code won't work:

    Code :
    domShader_GLSL* newShaderGLSL = daeSafeCast<domShader_GLSL >( intoPass_GLSL->createElement(COLLADA_ELEMENT_SHADER) );
    if (!newShaderGLSL->isAttributeSet("stage"))

    This code crashes in the isAttributeSet()-check ... it seems like some members of the newly created daeElement are not correctly initialized and assertion fails while accessing _validAttributeArray[i]; in the method daeElement::isAttributeSet( daeString attrName ).

    If I create the element with createAndPlace I don't get those troubles.

    Is the createElement() element intended to be used like this at all?

  2. #2
    Senior Member
    Join Date
    Aug 2005
    That is highly odd. Both daeElement::createElement(daeString) and daeElement::createAndPlace(daeString) start off with this line of code
    Code :
    daeElementRef elem = _meta->create(className);
    Then the only difference is createAndPlace calls the placeElement function before returning and create just returns elem.

    Are you sure that newShaderGLSL is not NULL.
    OHHHHHHHHH I figured it out. Its ref counting. you are storing the return value from createElement (a daeElementRef) as a *. When you createElement your ref count is 1. But since you don't keep the ref it gets deleted at the end of that line of code. But createAndPlace will place the element which increased the ref count to 2 or more (there may be another ref in the daeDocument or _contents array).

    That is the problem. Try this code instead
    Code :
    daeSmartRef<domShader_GLSL> newShaderGLSL = daeSafeCast<domShader_GLSL >( intoPass_GLSL->createElement(COLLADA_ELEMENT_SHADER) );
    if (!newShaderGLSL->isAttributeSet("stage"))


  3. #3
    that was it, thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean