From 812b7ae5ae32429b8828cee7f830ed4f70932457 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 14 Feb 2012 21:07:08 +1100 Subject: [PATCH] SITL: catch floating point errors if we get a FPE then log a message and exit --- libraries/Desktop/support/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/Desktop/support/main.cpp b/libraries/Desktop/support/main.cpp index e7a9f925a8..49528f542b 100644 --- a/libraries/Desktop/support/main.cpp +++ b/libraries/Desktop/support/main.cpp @@ -15,6 +15,13 @@ void loop(void); // the state of the desktop simulation struct desktop_info desktop_state; +// catch floating point exceptions +static void sig_fpe(int signum) +{ + printf("ERROR: Floating point exception\n"); + exit(1); +} + static void usage(void) { printf("Options:\n"); @@ -31,6 +38,8 @@ int main(int argc, char * const argv[]) desktop_state.slider = false; gettimeofday(&desktop_state.sketch_start_time, NULL); + signal(SIGFPE, sig_fpe); + while ((opt = getopt(argc, argv, "swhr:H:")) != -1) { switch (opt) { case 's':