patrikhuber / eos

A lightweight 3D Morphable Face Model library in modern C++
Apache License 2.0
1.89k stars 596 forks source link

Boost program_options runtime error in Debug mode #284

Closed pantelis-kan closed 4 years ago

pantelis-kan commented 4 years ago

Hello! I'm having an issue with fit-model.exe. The eos.sln and INSTALL target were successfully built with VS2019 x64. When I try to run fit-model.exe I get a Visual C++ Runtime Error and the program aborts. I used the Debugger in VS, and it catched a bad_alloc. The program crashed in line 72 of the file fit-model.cpp , in the very first try block after main():

po::options_description desc("Allowed options");

Boost x64 is installed with vcpkg in the default path. My issue is quite similar to this one : https://github.com/patrikhuber/eos/issues/43 but I can't find a way to resolve this.

patrikhuber commented 4 years ago

Hi,

I think you likely have some issue with boost or your build process (or perhaps the command line arguments that you give to fit-model), and nothing related to eos / fit-model. I would recommend to use a real debug build (not just attach the debugger to a release build) and step through the code line-by-line. Maybe it also has problems finding your Boost DLLs or something like that. Stackoverflow might be the better place to ask for help.

Also, there's nothing forcing you to use boost::program_options to use eos, you can just use the library and replace that part with your own argument parsing.

pantelis-kan commented 4 years ago

Ok so the error happens when I build Debug x64 in VS. The Release x64 build works perfectly.

patrikhuber commented 4 years ago

This really does not sound like an issue with eos. I recommend you follow some of the suggestions I outlined above.

isaac868 commented 2 years ago

I know this is completely unrelated to the eos project, but I figured out a solution to this for anyone that runs into it in the future. For some reason if the vcpkg toolchain file is not specified, CMake uses the release configuration for boost, even if you're compiling in debug. The issue I ran into is the debug MSVC std::string is not abi compatible with the release std::string, so when a string was passed to boost:program_options it would crash with a bad_alloc exception. The solution for me was to include "CMAKE_TOOLCHAIN_FILE": "C:\vcpkg\scripts\buildsystems\vcpkg.cmake" in my CMakePresets.json file to specify the vcpkg toolset and the problem so longer occurred.

patrikhuber commented 2 years ago

@isaac868 Nice that you got to the bottom of this - I guess the key is to follow vcpkg's readme instructions :-). Also I think (but am not 100% sure) that if you do vcpkg integrate install, then VS will find and use vcpkg automatically, and specifying the toolchain file in CMakePresets.json is likely not needed.