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

Add main function wrapper to catch exceptions and avoid annoying error popup on windows #768

Merged
merged 11 commits into from
May 16, 2020
1 change: 1 addition & 0 deletions src/aliceVision/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Headers
set(system_files_headers
cpu.hpp
main.hpp
MemoryInfo.hpp
system.hpp
Timer.hpp
Expand Down
44 changes: 44 additions & 0 deletions src/aliceVision/system/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is part of the AliceVision project.
// Copyright (c) 2020 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

/**
* @file \c main() function wrapper
* Provides an implementation of \c main() that automatically catches and logs
* otherwise unhandled exceptions.
*
* To use this wrapper you need to change your source file containing \c main() as such:
* 1. Include this header
* 2. Rename \c main() to \c aliceVision_main()
*/

#include "Logger.hpp"

#include <stdexcept>

/**
* @brief Name of the application entry function, replacing \c main().
*/
int aliceVision_main(int argc, char* argv[]);

// Inline to ensure the right main() is used (libf2c also has one...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a more explicit comment, like:

// Implementation of the unique main entry point.
// This method will call aliceVision_main and catch the exceptions to
// log the error message and avoid seg fault on exception on windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I expanded the comment.

int main(int argc, char* argv[])
{
try
{
return aliceVision_main(argc, argv);
}
catch(const std::exception& e)
{
ALICEVISION_LOG_FATAL(e.what());
}
catch(...)
{
ALICEVISION_LOG_FATAL("Unknown exception");
}
return EXIT_FAILURE;
}
3 changes: 2 additions & 1 deletion src/software/pipeline/main_cameraCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <aliceVision/calibration/exportData.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/config.hpp>

Expand Down Expand Up @@ -48,7 +49,7 @@
namespace bfs = boost::filesystem;
namespace po = boost::program_options;

int main(int argc, char** argv)
int aliceVision_main(int argc, char** argv)
{
// Command line arguments
bfs::path inputPath;
Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_cameraInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <aliceVision/sfmDataIO/viewIO.hpp>
#include <aliceVision/sensorDB/parseDatabase.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>

#include <boost/program_options.hpp>
Expand Down Expand Up @@ -167,7 +168,7 @@ inline std::istream& operator>>(std::istream& in, EGroupCameraFallback& s)
* @brief Create the description of an input image dataset for AliceVision toolsuite
* - Export a SfMData file with View & Intrinsic data
*/
int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
5 changes: 4 additions & 1 deletion src/software/pipeline/main_cameraLocalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <aliceVision/sfmDataIO/sfmDataIO.hpp>
#include <aliceVision/robustEstimation/estimators.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>

#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -60,7 +61,7 @@ std::string myToString(std::size_t i, std::size_t zeroPadding)
return ss.str();
}

int main(int argc, char** argv)
int aliceVision_main(int argc, char** argv)
{
/// the calibration file
std::string calibFile;
Expand Down Expand Up @@ -519,4 +520,6 @@ int main(int argc, char** argv)
ALICEVISION_COUT("Mean time for localization: " << bacc::mean(stats) << " [ms]");
ALICEVISION_COUT("Max time for localization: " << bacc::max(stats) << " [ms]");
ALICEVISION_COUT("Min time for localization: " << bacc::min(stats) << " [ms]");

return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/matching/IndMatch.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/config.hpp>

Expand All @@ -29,7 +30,7 @@ namespace po = boost::program_options;
namespace fs = boost::filesystem;

/// Compute the structure of a scene according existing camera poses.
int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_depthMapEstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <aliceVision/mvsUtils/MultiViewParams.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/gpu/gpu.hpp>

Expand All @@ -28,7 +29,7 @@ using namespace aliceVision;

namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_depthMapFiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/mvsUtils/MultiViewParams.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>

#include <aliceVision/depthMap/RefineRc.hpp>
Expand All @@ -28,7 +29,7 @@ using namespace aliceVision;

namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_featureExtraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <aliceVision/system/MemoryInfo.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/config.hpp>

Expand Down Expand Up @@ -254,7 +255,7 @@ class FeatureExtractor

/// - Compute view image description (feature & descriptor extraction)
/// - Export computed data
int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_featureMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <aliceVision/matchingImageCollection/GeometricFilterType.hpp>
#include <aliceVision/matching/pairwiseAdjacencyDisplay.hpp>
#include <aliceVision/matching/io.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/feature/selection.hpp>
Expand Down Expand Up @@ -86,7 +87,7 @@ void getStatsMap(const PairwiseMatches& map)
/// - Compute putative local feature matches (descriptors matching)
/// - Compute geometric coherent feature matches (robust model estimation from putative matches)
/// - Export computed data
int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_globalSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/sfm/pipeline/global/ReconstructionEngine_globalSfM.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>

#include <boost/program_options.hpp>
Expand All @@ -29,7 +30,7 @@ using namespace aliceVision;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_imageMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <aliceVision/voctree/VocabularyTree.hpp>
#include <aliceVision/voctree/databaseIO.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/config.hpp>

Expand Down Expand Up @@ -543,7 +544,7 @@ void conditionVocTree(const std::string& treeName, bool withWeights, const std::
}
}

int main(int argc, char** argv)
int aliceVision_main(int argc, char** argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_incrementalSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aliceVision/feature/imageDescriberCommon.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/types.hpp>
#include <aliceVision/config.hpp>
Expand Down Expand Up @@ -70,7 +71,7 @@ bool retrieveViewIdFromImageName(const sfmData::SfMData& sfmData,
}


int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_meshDecimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/mvsUtils/common.hpp>

Expand All @@ -30,7 +31,7 @@ using namespace aliceVision;
namespace bfs = boost::filesystem;
namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_meshDenoising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/mvsUtils/common.hpp>

Expand All @@ -32,7 +33,7 @@ using namespace aliceVision;
namespace bfs = boost::filesystem;
namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_meshFiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/mesh/MeshEnergyOpt.hpp>
#include <aliceVision/mesh/Texturing.hpp>
Expand All @@ -24,7 +25,7 @@ using namespace aliceVision;
namespace bfs = boost::filesystem;
namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_meshResampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/mvsUtils/common.hpp>

Expand All @@ -32,7 +33,7 @@ using namespace aliceVision;
namespace bfs = boost::filesystem;
namespace po = boost::program_options;

int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_meshing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <aliceVision/mvsUtils/fileIO.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/Timer.hpp>

#include <boost/program_options.hpp>
Expand Down Expand Up @@ -129,7 +130,7 @@ void removeLandmarksWithoutObservations(sfmData::SfMData& sfmData)
}


int main(int argc, char* argv[])
int aliceVision_main(int argc, char* argv[])
{
system::Timer timer;

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_panoramaCompositing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/*Reading command line options*/
#include <boost/program_options.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/main.hpp>

/*IO*/
#include <fstream>
Expand Down Expand Up @@ -853,7 +854,7 @@ class LaplacianCompositer : public Compositer {
size_t _bands;
};

int main(int argc, char **argv) {
int aliceVision_main(int argc, char **argv) {

/**
* Program description
Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_panoramaEstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <aliceVision/sfm/utils/alignment.hpp>
#include <aliceVision/system/Timer.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/image/all.hpp>

Expand Down Expand Up @@ -42,7 +43,7 @@ inline std::istream& operator>>(std::istream& in, std::pair<int, int>& out)
return in;
}

int main(int argc, char **argv)
int aliceVision_main(int argc, char **argv)
{
// command-line parameters

Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_panoramaExternalInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <aliceVision/image/all.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/numeric/numeric.hpp>
#include <aliceVision/sfmData/SfMData.hpp>
#include <aliceVision/sfmDataIO/sfmDataIO.hpp>
Expand All @@ -20,7 +21,7 @@ namespace po = boost::program_options;
namespace fs = boost::filesystem;
namespace pt = boost::property_tree;

int main(int argc, char * argv[]) {
int aliceVision_main(int argc, char * argv[]) {
std::string verboseLevel = system::EVerboseLevel_enumToString(system::Logger::getDefaultVerboseLevel());
std::string externalInfoFilename = "";
std::string sfmInputDataFilename = "";
Expand Down
3 changes: 2 additions & 1 deletion src/software/pipeline/main_panoramaWarping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/*Reading command line options*/
#include <boost/program_options.hpp>
#include <aliceVision/system/cmdline.hpp>
#include <aliceVision/system/main.hpp>

/*IO*/
#include <fstream>
Expand Down Expand Up @@ -1088,7 +1089,7 @@ bool computeOptimalPanoramaSize(std::pair<int, int> & optimalSize, const sfmData
return true;
}

int main(int argc, char **argv) {
int aliceVision_main(int argc, char **argv) {

/**
* Program description
Expand Down
Loading