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

Conditional jump or move depends on uninitialised value(s) #2089

Closed
mdenhoedt opened this issue Mar 12, 2016 · 10 comments
Closed

Conditional jump or move depends on uninitialised value(s) #2089

mdenhoedt opened this issue Mar 12, 2016 · 10 comments

Comments

@mdenhoedt
Copy link

This is the latest commit I have. I am running Ubuntu 14.04 LTS.

Valgrind is giving me the following error:

==6091== Conditional jump or move depends on uninitialised value(s)
==6091==    at 0x48801D: osrm::engine::RouteNames osrm::engine::extractRouteNames<osrm::engine::datafacade::BaseDataFacade<osrm::contractor::QueryEdge::EdgeData>, osrm::engine::detail::Segment>(std::vector<osrm::engine::detail::Segment, std::allocator<osrm::engine::detail::Segment> >&, std::vector<osrm::engine::detail::Segment, std::allocator<osrm::engine::detail::Segment> >&, osrm::engine::datafacade::BaseDataFacade<osrm::contractor::QueryEdge::EdgeData> const*) 
==6091==    by 0x48A232: osrm::engine::ApiResponseGenerator<osrm::engine::datafacade::BaseDataFacade<osrm::contractor::QueryEdge::EdgeData> >::DescribeRoute(osrm::engine::RouteParameters const&, osrm::engine::InternalRouteResult const&, osrm::util::json::Object&) 
==6091==    by 0x48D314: osrm::engine::plugins::ViaRoutePlugin<osrm::engine::datafacade::BaseDataFacade<osrm::contractor::QueryEdge::EdgeData> >::HandleRequest(osrm::engine::RouteParameters const&, osrm::util::json::Object&) 
==6091==    by 0x498BBE: osrm::engine::Engine::RunQuery(osrm::engine::RouteParameters const&, osrm::util::json::Object&)

My code looks just like the example/example.cpp:

osrm::EngineConfig engine_config;
engine_config.server_paths["ramindex"] = OSRM_FILE + ".ramIndex";
engine_config.server_paths["fileindex"] = OSRM_FILE + ".fileIndex";
engine_config.server_paths["hsgrdata"] = OSRM_FILE + ".hsgr";
engine_config.server_paths["nodesdata"] = OSRM_FILE + ".nodes";
engine_config.server_paths["edgesdata"] = OSRM_FILE + ".edges";
engine_config.server_paths["coredata"] = OSRM_FILE + ".core";
engine_config.server_paths["geometries"] = OSRM_FILE + ".geometry";
engine_config.server_paths["timestamp"] = OSRM_FILE + ".timestamp";
engine_config.server_paths["namesdata"] = OSRM_FILE + ".names";
engine_config.use_shared_memory = false;

osrm::OSRM *machine = new osrm::OSRM(engine_config);
osrm::RouteParameters route_parameters;
route_parameters.service = "viaroute";
route_parameters.geometry = false;
route_parameters.AddCoordinate(this->latitude, this->longitude);
route_parameters.AddCoordinate(other.latitude, other.longitude);
osrm::json::Object json_result;

machine->RunQuery(route_parameters, json_result);

What am I missing?

@daniel-j-h
Copy link
Member

Looks like it comes from within libosrm and it's not your fault.

Could you do me a favor and checkout the rewrite/new-api branch (this is what will become osrm v5 in a little while). Take a look at the example we re-wrote: https://github.com/Project-OSRM/osrm-backend/blob/rewrite/new-api/example/example.cpp

Another example is this HTTP server using the v5 libosrm preview: https://github.com/daniel-j-h/libosrm-http-casablanca (take a look at main.cc).

Sidenote: you have a memory leak, you new but don't delete. In modern C++ you don't need any of this. Just embrace value-types and do it like this:

OSRM osrm;
..
osrm.Route(..);
..
}  // scope exit calls osrm's destructor automatically and deterministically cleaning up

@mdenhoedt
Copy link
Author

Thanks for you quick response. I checked out to the rewrite/new-api branch, but I can't compile the code, I get the following error:

In file included from /usr/local/include/osrm/route_parameters.hpp:31:0,
                 from /[project_dir]/logic/osrm_helper.h:6,
                 from /[project_dir]/logic/osrm_helper.cpp:1:
/usr/local/include/osrm/engine/api/route_parameters.hpp:31:42: fatal error: engine/api/base_parameters.hpp: No such file or directory
 #include "engine/api/base_parameters.hpp"
                                          ^
compilation terminated.

When running sudo cmake --build . --target install I does say something about that file:
-- Up-to-date: /usr/local/include/osrm/engine/api/base_parameters.hpp. I can also confirm there is a file on that location. However in osrm-backend/src/engine/api there is no file base_parameters.hpp.

@daniel-j-h
Copy link
Member

The header is in include/engine/api and not in src/engine/api. Can you do the following to make sure you don't have files from multiple versions installed:

sudo rm -rf /usr/local/include/osrm

Then checkout the rewrite/new-api branch. Compile and install libosrm via:

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1
cmake --build .
sudo cmake --build . --target install

Then build the example in the repository:

mkdir example/build
cd example/build
cmake .. -DCMAKE_BUILD_TYPE=Release

The project I linked to does exactly the same (without installing it system-wide) for a v5 libosrm from the rewrite/new-api branch: https://github.com/daniel-j-h/libosrm-http-casablanca/blob/master/deps.sh

Hope that helps

@mdenhoedt
Copy link
Author

Uhmm, good point. I now have successfully running this as latest commit. But I will try out the rewrite/new-api branch out again. (Don't get me wrong, but please note that I get a bit annoyed a lot of different APIs).

@daniel-j-h
Copy link
Member

Great that it helped!

The current re-write of what will become v5 is the first major one and it's necessary e.g. for improved and actual usable guidance. It also improves the libosrm API in that you no longer have to pass strings around, but instead have type-safe services you can call like Route(..), and a ton of other features we could work in as we were breaking compatibility once here.

If you want to give libosrm a shot you're fine, but for anything serious I recommend starting out with v5.

@mdenhoedt
Copy link
Author

I check out again to the rewrite/new-api and did all you said I should do. And the example.cpp compiled straight away. However at runtime it didn't work:

user@user:~/Documents/osrm-backend/example/build$ ./osrm-example 
./osrm-example: error while loading shared libraries: libosrm.so: cannot open shared object 
                file: No such file or directory

I modified my CMakeLists.txt file in my own project with the help of the one stated in the example folder and now my project compiles as well. But at runtime the same error occurs.

@daniel-j-h
Copy link
Member

I assume libosrm.so got installed to /usr/local/lib/libosrm.so. When you do

ldd osrm-example

do you see a line saying

libosrm.so => /usr/local/lib/libosrm.so

From the error above it looks to me that the loader can not find libosrm.so, that is you probably see instead

libosrm.so => not found

In this case, your loader does not look into /usr/local/lib by default or the shared library cache is not up-to-date. Try running

sudo ldconfig
ldd osrm-example  # libosrm now found?

to update the shared library cache. If that does not work, then your loader does not look at /usr/local/lib for libraries and you can fix this by either adding the path to /etc/ld.so.conf or by prepending it to LD_LIBRARY_PATH as in

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
ldd osrm-example  # now libosrm.so should be found!
./osrm-example

Note: another option would be to simply build a statically linked libosrm.a by following the steps above but setting -DBUILD_SHARED_LIBS=0 and then linking this one in (make sure you really link in the archive and not a stale libosrm.so). Or even install libosrm.so globally (my guess is /usr/lib) where your loader finds it by default.

@mdenhoedt
Copy link
Author

sudo ldconfig did the trick 😄. One little question what are the best RouteParameters when you are only interested in the distance and duration of the route? Are there certain RouteParameters that can speed-up the calculation?

@daniel-j-h
Copy link
Member

Definitely turn off alternatives, that's probably the most expensive one. You will probably only seeing improvements when doing a massive amount of queries. In that case, just play around with it a bit and profile!

In case you're doing incremental queries you can get a hint which you have to provide for subsequent queries. This skips the geospatial lookup for locations for which you provide hints.

@mdenhoedt
Copy link
Author

Ok, thanks. And yes I am doing a massive amount of queries. I will close this issue, since everything is solved.

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