memory access violation at address when using Iterators inside a while loop (c++)

2

so when I try to iterate over the "ObserverTree"(typedef std::map<std::string, std::vector<std::string>> ChannelTree; typedef std::map<std::string, ChannelTree> ObserverTree;) im getting this error

unknown location(0): fatal error in "LoadTest": memory access violation at address: 0xfffffffffffffff8: no mapping at fault address

in the line observerIndicatorMap.insert(std::pair<std::string, int>(observerIterator->first, i));

if this line is commented out I get this error

unknown location(0): fatal error in "LoadTest": signal: SIGSEGV, si_code: 0 (memory access violation at address: 0x00000080)

in the line dataFieldIterator = channelIterator->second.begin();

This is the whole method:

void roboCorder::dataHandling::loadingUnit::RecordDataLoadingStrategy::createReplayObservers()
{
    int observerAmount = metaData.getObservertree().size();
    std::vector<roboCorder::activeUnits::ReplayObserverPtr>replayObservers(observerAmount);
    dataHandling::MetaData::ObserverTree::iterator observerIterator = metaData.getObservertree().begin();
for (int i = 0; i < observerAmount; i++, observerIterator++)
{
    replayObservers[i] = new activeUnits::ReplayObserver(observerIterator->first);
    observerIndicatorMap.insert(std::pair<std::string, int>(observerIterator->first, i));
    dataHandling::MetaData::ChannelTree::iterator channelIterator = observerIterator->second.begin();
    while (channelIterator != observerIterator->second.end())
    {
        //the second argument is the channel description but we dont save that so we just give the channel name as description.
        //replayObservers[i]->offerChannel(observerIterator->first, observerIterator->first);
        std::vector<std::string>::iterator dataFieldIterator;
        dataFieldIterator = channelIterator->second.begin();
        while (dataFieldIterator != channelIterator->second.end())
        {
            //replayObservers[i]->offerDataField(channelIterator->first, dataFieldIterator.operator * (),  firstValue?  , dataFieldIterator.operator * ());
            dataFieldIterator++;
        }
        channelIterator++;
    }
}

}

Here is the requested LoadTest method. As you can see its a test case. TestFileIdentifier is the path to an existing and valid test file.

BOOST_AUTO_TEST_CASE(LoadTest)
{
std::cout << std::endl << "--> LoadTest starts..." << std::endl;
Init loadTest;

try
{
    loadTest.dataHandlingController.loadRecord(TestFileIdentifier);
    std::cout << "done" << std::endl;
}
catch (std::exception e)
{
    std::cout << e.what() << std::endl;
    BOOST_FAIL("Loading caused an exception! Test Failed!");
}

}

And the loadRecord method is here. There are still methods missing thats why there is a dummy output.

roboCorder::dataHandling::DataReloaderListPtr roboCorder::dataHandling::DataHandlingController::loadRecord(std::string dataIdentifier)
{
loader->setRecordingIdentifier(dataIdentifier);
loader->loadMetaData();
loader->createReplayObservers();

return DataReloaderListPtr(); //dummy output.

}

c++
c++11
asked on Stack Overflow Feb 10, 2016 by user5906817 • edited Feb 10, 2016 by user5906817

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0