Skip to content

Commit 0e1926f

Browse files
Wait for log messages to be flushed before aborting Maya
This is to allow the assertions to be fully printed to the log files before Maya exits. We wait for 1 second, which may seem excessive, but I'd rather wait .9 seconds too long than have critical debug information cut off.
1 parent e7bbe2f commit 0e1926f

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • lib/mmsolverlibs/include/mmsolverlibs

lib/mmsolverlibs/include/mmsolverlibs/assert.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <ostream>
3333
#include <sstream>
3434
#include <string>
35+
#include <thread>
3536

3637
// Define our own debug flag if not already defined.
3738
#ifndef MMSOLVER_DEBUG
@@ -226,6 +227,13 @@ inline void print_todo(std::ostream& ostream, const char* file, const int line,
226227
ostream << std::flush;
227228
}
228229

230+
inline void wait_abort() {
231+
// Give the OS a moment to flush buffers.
232+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
233+
234+
std::abort();
235+
}
236+
229237
} // namespace assert
230238
} // namespace mmsolverlibs
231239

@@ -238,7 +246,7 @@ inline void print_todo(std::ostream& ostream, const char* file, const int line,
238246
::mmsolverlibs::assert::print_assert(std::cerr, __FILE__, \
239247
__LINE__, __func__, \
240248
#condition, ss.str()); \
241-
std::abort(); \
249+
::mmsolverlibs::assert::wait_abort(); \
242250
} \
243251
} while (0)
244252

@@ -252,7 +260,7 @@ inline void print_todo(std::ostream& ostream, const char* file, const int line,
252260
::mmsolverlibs::assert::print_assert(std::cerr, __FILE__, \
253261
__LINE__, __func__, \
254262
#condition, ss.str()); \
255-
std::abort(); \
263+
::mmsolverlibs::assert::wait_abort(); \
256264
} \
257265
} while (0)
258266
#else
@@ -297,7 +305,7 @@ inline void print_todo(std::ostream& ostream, const char* file, const int line,
297305
ss << __VA_ARGS__; \
298306
::mmsolverlibs::assert::print_panic(std::cerr, __FILE__, __LINE__, \
299307
__func__, ss.str()); \
300-
std::abort(); \
308+
::mmsolverlibs::assert::wait_abort(); \
301309
} while (0)
302310

303311
// Quit the program, showing a message why and where the failure happened.
@@ -307,7 +315,7 @@ inline void print_todo(std::ostream& ostream, const char* file, const int line,
307315
ss << __VA_ARGS__; \
308316
::mmsolverlibs::assert::print_todo(std::cerr, __FILE__, __LINE__, \
309317
__func__, ss.str()); \
310-
std::abort(); \
318+
::mmsolverlibs::assert::wait_abort(); \
311319
} while (0)
312320

313321
// Clean up the defines made in this file.

0 commit comments

Comments
 (0)