Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:18:04+00:00 2026-06-07T08:18:04+00:00

I am writing a small game engine as a summer project, and am struggling

  • 0

I am writing a small game engine as a summer project, and am struggling a little with the STL map.

I have declared a class RenderList to hold objects. The RenderList will be passed to a Renderer class to do the work.

The RenderList has a map<std::string,Entity*> objects;

That all works, till I try to obtain an Entity* from the map and I get:

Assertion failed, in vc/include/xtree
Expression: map/set iterator not dereferencable.

This is the code to retrieve the pointer.

Entity* RenderList::getByName(std::string str){
    return objects.find(str)->second;
}

I need it to hold a pointer and not the actual object, as there are different sub-classes of Entity which I’ll need.

I am fairly new to the STL, should I not store pointers in a map?

Surely I should be allowed to do this, or is it a better idea to store objects instead?

And finally, am I simply doing it wrong!?

Hope this question is not a duplicate, I did do a quick search beforehand. Also if this would be better in the GameDev Stack I’ll post it there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:18:05+00:00Added an answer on June 7, 2026 at 8:18 am

    If the key is not found then map::find(key) returns a “past-the-end” iterator, i.e. the value returned by map::end(), and that iterator doesn’t point to any element so can’t be dereferenced. You do not check what find returns before dereferencing it.

    Are you sure they key is in the map?

    You probably want to do something like return NULL if the key isn’t found, which you can check for by comparing the returned iterator to end e.g.

    Entity* RenderList::getByName(std::string str){
      map_type::iterator it = objects.find(str);
      if (it == objects.end())
        return NULL;
      return it->second;
    }
    

    Where RenderList defines the typedef:

    typedef map<std::string,Entity*> map_type;
    

    (N.B. I always make my classes define typedefs for the containers I use as implementation details, because it’s much easier to write map_type::iterator than map<std::string,Entity*>::iterator and because if I change the container to something else I don’t have to change all the code using it to e.g. map<std::string,shared_ptr<Entity>>::iterator I can just leave it as map_type::iterator and it still works perfectly.)

    Regarding the general design, can you store a boost::shared_ptr<Entity> or std::tr1::shared_ptr<Entity> instead of a raw pointer? It will be much safer and simpler to manage the object lifetimes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started creating a small game engine for an independent project. When writing the
I have am writing a small game using Applet. I want to be able
I am currently considering writing a small game. It is essentially a map where
I have writing a small shooting game in cocos2d. Winning the game is to
I am writing a small Android game using a SurfaceView class. The outline of
A little background: I'm writing a small word based maze game starting with a
I am writing a small game engine for XNA. Right now my entity manager
I have the beginnings of a small multiplayer game that I'm writing in python
I am writing a colouring game for small children, where I have a black
I am writing a small RPG game engine with Lua/love2d, and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.