Results 1 to 4 of 4

Thread: Segfault when saving xml

  1. #1
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default Segfault when saving xml

    Hello, I'm saving some modified CL_DomDocument object. Here is some code:
    Base.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <SomeTag>
    </SomeTag>
    Additional.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <SomeTag>
        <SomeChild name="childI" />
    </SomeTag>
    And c++ code:
    Code:
    CL_File file("Base.xml");
    CL_DomDocument document(file);
    CL_DomNodeList childList = document.get_child_nodes();
    
    CL_File file2("Additional.xml");
    CL_DomDocument document2(file);
    CL_DomNodeList childList2 = document2.get_first_child().get_child_nodes();
    
    for (int i=0; i < childList.get_length(); ++i)
    {
       if (childList.item(i).get_node_name() == "SomeTag")
       {
          childList.item(i).append_child(childList2.item(0));
       }
    }
    
    CL_File writeFile("out.xml", CL_File::create_always, CL_File::access_write);
    document.save(writeFile);
    After running in out.xml there is text:
    <SomeTag>
    And then program segfaults:
    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff6559994 in CL_DomNode::get_node_type() const () from /usr/lib/libclan22Core-2.2.so.1
    (gdb) backtrace
    #0  0x00007ffff6559994 in CL_DomNode::get_node_type() const () from /usr/lib/libclan22Core-2.2.so.1
    #1  0x00007ffff6559ee9 in CL_DomNode::is_null() const () from /usr/lib/libclan22Core-2.2.so.1
    #2  0x00007ffff654f230 in CL_DomDocument::save(CL_IODevice&, bool) () from /usr/lib/libclan22Core-2.2.so.1
    #3  0x0000000000403d0b in work() ()
    #4  0x00000000004048b4 in DisplayProgram::main(std::vector<CL_String8, std::allocator<CL_String8> > const&) ()
    #5  0x00007ffff7bddf86 in main () from /usr/lib/libclan22App-2.2.so.1
    #6  0x00007ffff5763c4d in __libc_start_main () from /lib/libc.so.6
    #7  0x0000000000403109 in _start ()

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Sounds like a bug in clanlib.

    Probably, a "is_null" check is missing somewhere during the save.

    Hope you find it

  3. #3
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Okay, I gonna look at sources.

  4. #4
    Squire
    Join Date
    Oct 2010
    Location
    Copenhagen, Denmark
    Posts
    10

    Default

    IIRC, you need to import the node into the DomDocument when copying nodes from one document to another. Something like this should do the trick:

    Code:
    ...
    for (int i=0; i < childList.get_length(); ++i)
    {
       if (childList.item(i).get_node_name() == "SomeTag")
       {
          childList.item(i).append_child(document.import_node(childList2.item(0), true));
       }
    }
    ...

Similar Threads

  1. Novashell binary gives segfault.
    By prat in forum Novashell Game Creation System
    Replies: 13
    Last Post: 01-02-2011, 06:55 PM
  2. Segfault with FontTest program
    By keph in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-07-2009, 11:31 PM
  3. simple ClanLib example problem - segfault
    By phx_one in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 02-17-2008, 12:54 AM
  4. pillbugs and saving
    By in forum Dink Smallwood HD
    Replies: 2
    Last Post: 05-01-2005, 10:51 PM
  5. saving game
    By lowec in forum Dink Smallwood HD
    Replies: 1
    Last Post: 01-09-2005, 12:25 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •