Bug 2230 - Crash when loading an XML file containing no nodes
Crash when loading an XML file containing no nodes
Status: NEW
Product: netanim
Classification: Unclassified
Component: animator
PC Linux
: P5 major
Assigned To: John Abraham
Depends on:
  Show dependency treegraph
Reported: 2015-11-27 05:32 EST by Beestre84
Modified: 2015-11-27 11:59 EST (History)
1 user (show)

See Also:

3 diffs with patch suggestions (2.53 KB, text/plain)
2015-11-27 05:32 EST, Beestre84

Note You need to log in before you can comment on or make changes to this bug.
Description Beestre84 2015-11-27 05:32:55 EST
Created attachment 2194 [details]
3 diffs with patch suggestions

Netanim crashes if one tries to load a file with no nodes (only anim tags inside), and if I remember correctly, even if the file contains nodes only. It will crash for sure, if no node with ID == 0 is present.

Please see the attachment for some possible (quick&dirty) changes.

I think the most important parts are in animpropertybrowser.cpp, postParse ():
a check for count == 0 will prevent the empty-file-crash.

Setting m_currentNodeId = AnimNodeMgr::getInstance()->cbegin()->first;
makes sure, that m_currentNodeId is a valid ID (but it looks awful).

Of course, if the node IDs always start at 0 and increase monotonically everything is fine either way. However, since NodeIdAnimNodeMap_t is a typedef to std::map instead of a simple vector, I suppose you want it to be more general.

I've added the functions cbegin and cend to iterate over all elements in the map. I might be completely wrong here, but as far as I understood the function AnimPropertyBroswer::setupNodeProperties (), you want to set up all nodes, not just the m_currentNodeId one. Sorry if I tried to 'improve' correct code here.

For the case that I'm not wrong so far, you probably want to change the following lines to use the iterator approach, too:

for (uint32_t i = 0; i < count; ++i)
      m_nodeIdSelector->addItem (QString::number (i)); //use it->first here

Thank you for your quick replies and commits!
Comment 1 Beestre84 2015-11-27 11:59:46 EST
Ok, the for loop in the browser breaks things. I'm sorry.