Answer :

Turns out the for loop did work.

Lesson Learned :

You might want to try putting something in it to see if the code inside actually executes....

As the title says I would like to loop trough a std::map filled with sf::Sprite*'s.

However when I try it like this :

(in .h file)    

std::map<std::string, sf::Texture*> textures;

(in .cpp file)

for (auto const &ent1 : textures)


It tells me that the Debug Assertion Failed!.

With this error "log" :

Program: C:\WINDOWS\SYSTEM32\MSVCP140D.dll File: c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtree Line: 237

Expression: map/set iterator not dereferencable

At this point I've tried reading some on how it works, and I don't understand what I'm doing wrong.

I've been playing around with it, removing some parts and adding new ones.

I'be been removing const, removing the & and combining those two.


closed as off-topic by Alexandre Vaillancourt, concept3d, Josh Jan 11 '16 at 16:25

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh
  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Alexandre Vaillancourt, concept3d
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Are you modifying textures inside the loop? \$\endgroup\$ – bornander Jan 11 '16 at 10:05
  • \$\begingroup\$ @bornander I'm not doing anything inside it. Since I'm not sure how yet. \$\endgroup\$ – BiiX Jan 11 '16 at 10:30
  • \$\begingroup\$ Can you compile & run the following code example in your cpp file? ideone.com/EOXzxr \$\endgroup\$ – Miklas Jan 11 '16 at 10:35
  • \$\begingroup\$ @Miklas Yes, that works with the output : 1 - 1, 10 - 10, 5 - 5, 1 - 1, 10 - 10, 5 - 5 \$\endgroup\$ – BiiX Jan 11 '16 at 10:39
  • 1
    \$\begingroup\$ Try const auto& ent1. I think the modifier might be in the wrong place. \$\endgroup\$ – Tyyppi_77 Jan 11 '16 at 10:54

It is likely that you have corrupted the underlying storage of your map object and the VC++ debug runtime has protection code that tests if the data structure and iterators are in a valid state to avoid more damage. Clobbering memory and other undefined behaviour can result in all sorts of amusing results.

When in doubt about the semantics of something, consider making a test project in which you explore the concept, and if you run into a bug, try to isolate it as far as possible to rule out things.

  • \$\begingroup\$ My English ins't the best and my programming isn't either, lol. Do you have some links on what a container and a safeguard is? Never heard of those before. Should I add the way I "insert" objects into my map s well? \$\endgroup\$ – BiiX Jan 11 '16 at 13:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.