averrin / libmapgen

Unity native plugin for procedural world generation
MIT License
19 stars 3 forks source link

Read acccess violation in Map::getRegionDistance #3

Open spacehamster opened 6 years ago

spacehamster commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

The older commit without smart pointer works great

averrin commented 6 years ago

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