Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read acccess violation in Map::getRegionDistance #3

Open
spacehamster opened this issue Jul 11, 2018 · 4 comments
Open

Read acccess violation in Map::getRegionDistance #3

spacehamster opened this issue Jul 11, 2018 · 4 comments

Comments

@spacehamster
Copy link
Contributor

spacehamster commented Jul 11, 2018

If i run the following

#include <mapgen/MapGenerator.hpp>
int main(int argc, char ** argv) {
    MapGenerator * mapgen = new MapGenerator(1600, 900);
    mapgen->setSeed(4000);
    mapgen->update();
    mapgen->startSimulation();
    delete mapgen;
}

I get a read access violation in Map::getRegionDistance trying to read from std::shared_ptrr.
I think this may be related to passing in a raw pointer Region * in Simulator.cpp makeRoad
and then casting them back to shared_ptr in LeastCostEstimate?
Or in AdjactedCost the micropather is given a reference to n which immediatly falls out of scope?

I tried changing

int result = pather->Solve(c->region.get(), oc->region.get() &path, &totalCost);

to

int result = pather->Solve(&(c->region), &(oc->region), &path, &totalCost);

and

for (auto n : r->neighbors) {

to

for (auto &n : r->neighbors) {

in AdjacentCost but then it crashes while trying to delete cities in removeBadPorts

@averrin
Copy link
Owner

averrin commented Jul 11, 2018

Seems like my recent commits which adds smart pointers are horrible =/
Try to use 121b512c155da94b59e7990f0a9226a19e78e2ed for mapgen-viewer
and dd14a6b5e491b0bce52b7f885f424e9621e0f740 for libmapgen

I am not very experienced c++ developer to fix segfaults quickly =( But if you can, i will be very grateful.

@averrin
Copy link
Owner

averrin commented Jul 11, 2018

I use pathfinding in my other project and with possibly better approach: https://github.com/averrin/lss/blob/master/src/game/location.cpp#L285

@spacehamster
Copy link
Contributor Author

The older commit without smart pointer works great

@averrin
Copy link
Owner

averrin commented Jul 11, 2018

Nice. I will move recent commits to experimental branches.
Thanks for using my code. Despite the problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants