Jump to content

Map iterator error happens in World::Update() if prev wolrd/scene was not removed before loading new scene


Go to solution Solved by Josh,

Recommended Posts

  • Dreikblack changed the title to Map iterator error happens in World::Update() if prev wolrd/scene was not removed before loading new scene
  • 1 month later...
Posted
On 1/31/2025 at 9:23 AM, Dreikblack said:

Checkout commit which was before removing prev game workaround fix:

How do I check out a specifica commit on Github? I don't know how to do this.

My job is to make tools you love, with the features you want, and performance you can't live without.

  • 4 months later...
  • Josh pinned this topic
  • Josh featured and unpinned this topic
  • Josh unfeatured this topic
Posted
12 hours ago, Dreikblack said:

To reproduce it you can checkout master branch and just comment or remove "game.reset();" line after comment "//to avoid random error in World::Update()" at 59 line

What file is this in? I am up to date on the master branch, but cannot find any occurance of the text "to avoid random error" in the project.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

This is what the update loop looks like. It is crashing on the last line where the iterator is incremented. It says the iterator is the end iterator. I do not know how this is possible. The list "entitieswithnewcomponents" just means "entities that have a component with an Update method".

Do you know what component is in use that has an Update() method that causes this?

		//Update components
		{
			auto it = entitieswithnewcomponents.begin();
			while (it != entitieswithnewcomponents.end())
			{
				auto e = (*it).lock();
				if (e == NULL)
				{
					it = entitieswithnewcomponents.erase(it);
					continue;
				}
				e->failedcomponentcalls = 0;
				for (auto c : e->components)
				{
					if (c->GetEnabled()) c->Update(); 
				}
				if (e->failedcomponentcalls == e->components.size())
				{
					it = entitieswithnewcomponents.erase(it);
					continue;
				}
				++it;
			}
		}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

It looks like TopDownCamera was the last component that executed, but I do not see anything suspicious in there.

Are you doing anything like loading a scene in a component?

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Solution
Posted

The code I had originally should handle changes to the STL set just fine. I replaced it with this code, and the error no longer occurs. I still don't understand why. This seems like incorrect behavior in STL.

//https://www.leadwerks.com/community/topic/67870-map-iterator-error-happens-in-worldupdate-if-prev-wolrdscene-was-not-removed-before-loading-new-scene/
auto it = entitieswithnewcomponents.begin();
std::vector<std::shared_ptr<Entity> > entities;
entities.reserve(entitieswithnewcomponents.size());

while (it != entitieswithnewcomponents.end())
{
	auto e = (*it).lock();
	if (e == NULL)
	{
		it = entitieswithnewcomponents.erase(it);
		continue;
	}
	entities.push_back(e);
	++it;
}

for (auto e : entities)
{
	e->failedcomponentcalls = 0;
	for (auto c : e->components)
	{
		if (c->GetEnabled()) c->Update();
	}
	if (e->failedcomponentcalls == e->components.size())
	{
		auto it = entitieswithnewcomponents.find(e);
		if (it != entitieswithnewcomponents.end()) entitieswithnewcomponents.erase(it);
	}
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

BTW, the reason your project takes so long to compile is because every file is set to create a precompiled header. Only Leadwerks.cpp should have this set to Create. Every other file should be set to Use, or for SelectDevice.cpp, "Not using precompiled header".

My job is to make tools you love, with the features you want, and performance you can't live without.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...