| 56 | | Dealing with the Invalid Parameter exception (0xc000000d): |
| 57 | | |
| 58 | | Starting with Visual Studio 2005, Microsoft re-vamped the whole C Runtime Library. Part of the re-vamp process was to do parameter checking on each function. Places that would normally return a NULL value now cause a structured exception to be thrown. |
| 59 | | |
| 60 | | The nature of this structured exception is different than most as they specifically coded it so that it will not engage the BOINC Runtime Debugger and it'll display a dialog box asking the user if they wish to debug the error. If the user cancels the error code 0xc000000d is returned without any more information. |
| 61 | | |
| 62 | | To get more information with this error you'll need to create a function like this: |
| 63 | | {{{ |
| 64 | | #ifdef _WIN32 |
| | 56 | Recent versions of Visual Studio include changes to the C Runtime Library which throw up this error when an invalid parameter is passed to various functions: |
| | 57 | |
| | 58 | [[Image(runtimerror.png)]] |
| | 59 | |
| | 60 | To prevent this dialog from being displayed and presenting a bad user experience on the BOINC platform, please add this to your applications initialization: |
| | 61 | {{{ |
| | 62 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| | 63 | _set_invalid_parameter_handler(AppInvalidParameterHandler); |
| | 64 | #endif |
| | 65 | }}} |
| | 66 | |
| | 67 | Where AppInvalidParameterHandler() is defined as: |
| | 68 | {{{ |
| | 69 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 83 | | |
| 84 | | The following code block should be added after the call to boinc_diagnostics_init(): |
| 85 | | {{{ |
| 86 | | #ifdef _WIN32 |
| 87 | | // Every once and awhile something looks at a std::vector or some other |
| 88 | | // CRT/STL construct that throws an exception when an invalid parameter |
| 89 | | // is detected. In this case we should dump whatever information we |
| 90 | | // can and then bail. When we bail we should dump as much data as |
| 91 | | // possible. |
| 92 | | _set_invalid_parameter_handler(AppInvalidParameterHandler); |
| 93 | | #endif |
| 94 | | }}} |
| 95 | | |
| 96 | | When this issues happens in the future it'll describe which CRT function call was passed an invalid parameter and it should dump out the callstack for all threads. |
| 97 | | |
| 98 | | The function blocks above overwrite the default behavior of the CRT when an invalid parameter is detected. |
| 99 | | |