diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-02-11 12:04:27 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-02-11 12:04:27 +0000 |
| commit | 8aeb741ccbe2edb528e98a431bf55459a6836a9b (patch) | |
| tree | a14569b531d9867683a1ac1c94c8e0eb406906a8 /src/lib/util.cc | |
| parent | 4ba8772aef261da209bbb882325fd61a8b479fd7 (diff) | |
| parent | 22f2cd94132f93a159c2ce9fe263771cb5a5dbdf (diff) | |
Merge master.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index ef203c2bd..418d7b3e0 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -27,6 +27,7 @@ #include <iostream> #include <fstream> #include <climits> +#include <stdexcept> #ifdef DCPOMATIC_POSIX #include <execinfo.h> #include <cxxabi.h> @@ -93,7 +94,9 @@ using std::istream; using std::numeric_limits; using std::pair; using std::cout; +using std::bad_alloc; using std::streampos; +using std::set_terminate; using boost::shared_ptr; using boost::thread; using boost::lexical_cast; @@ -272,6 +275,33 @@ LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *) } #endif +/* From http://stackoverflow.com/questions/2443135/how-do-i-find-where-an-exception-was-thrown-in-c */ +void +terminate () +{ + static bool tried_throw = false; + + try { + // try once to re-throw currently active exception + if (!tried_throw++) { + throw; + } + } + catch (const std::exception &e) { + std::cerr << __FUNCTION__ << " caught unhandled exception. what(): " + << e.what() << std::endl; + } + catch (...) { + std::cerr << __FUNCTION__ << " caught unknown/unhandled exception." + << std::endl; + } + +#ifdef DCPOMATIC_POSIX + stacktrace (cout, 50); +#endif + abort(); +} + /** Call the required functions to set up DCP-o-matic's static arrays, etc. * Must be called from the UI thread, if there is one. */ @@ -308,7 +338,9 @@ dcpomatic_setup () boost::filesystem::path lib = app_contents (); lib /= "lib"; setenv ("LTDL_LIBRARY_PATH", lib.c_str (), 1); -#endif +#endif + + set_terminate (terminate); Pango::init (); libdcp::init (); @@ -926,3 +958,13 @@ time_round_up (DCPTime t, DCPTime nearest) DCPTime const a = t + nearest - 1; return a - (a % nearest); } + +void * +wrapped_av_malloc (size_t s) +{ + void* p = av_malloc (s); + if (!p) { + throw bad_alloc (); + } + return p; +} |
