Good practice about map and erasing in arrays


I have 2 classes one containing an ofImage, the other with a map of the first class. See Code below.
I got BAD ACCESS issue when sometimes i’m erasing elements of my map, the issue is inside the ++ iterator function.
What are the good practices to manage arrays of ofImage, i think it comes from ofImage because the same unit class without an ofImage member is doing well ?

Do I have to do a destructor, what do I have to put inside that destructor ? etc.

I know that’is some kind of basic classic issue of iterator and ofImage but… thanks for helping

Unit class
#pragma once

#include "ofMain.h"
#include "hospitalMeetingPoint.h"

class hospitalPicture : public hospitalMeetingPoint{

    float   mTimeStamp;
    float  mFadeInSec;
    float  mFadeOutSec;
    ofImage mImage;
    void setup(string _path, float _resizeRatio);
    void draw(bool _drawDebug, bool _drawImage);
    void refresh(){mTimeStamp = ofGetElapsedTimef();};
    float getAscTimeRatio();
    float getDescTimeRatio();
    void setFadeIn(float _fadeIn){mFadeInSec = _fadeIn;};
    void setFadeOut(float _fadeOut){mFadeOutSec = _fadeOut;};

Classs with the map

#include "ofMain.h"
#include "hospitalPicture.h"

class hospitalPictureManager {


    bool mIsPictureActive;
    map<string, hospitalPicture> mPicturePositions;

Indeed there’s nothing wrong ofImage, i got the same issue when i have simple entities with no ofImage as member.
But i still have issue, can someone help ?

Not sure what the issue is but. Usually and EXC_BAD_ACCESS is because your iterator is looping through something that has been deallocated or is corrupted. Did you try printing the size of the vector before you start your for loop? Also, can you show us how you initialize your map? If you can upload your code that would be helpful


Well i solved it with that, beign more careful of when to increment :

// -------------------------------------------------------------------------------------------
void hospitalPictureManager::update(){

    map<string, hospitalPicture>::iterator pic;
    int idx = 0;
    ofLogVerbose() << "Size of pictures map : " << mPicturePositions.size();
    pic = mPicturePositions.begin();
    while (pic != mPicturePositions.end()){
        if(pic->second.getAscTimeRatio() >= 1.0f){
            ofLogVerbose() << "This image deleted : " << ofToString(idx);
            ofLogVerbose() << "Size of pictures map : " << mPicturePositions.size();
    ofLogVerbose() << "Size of pictures map : " << mPicturePositions.size();