SDL_ASSERT_LEVEL影响到不同的断言是否起作用。
SDL_ASSERT_LEVEL可以被定义为下列的值
| SDL_ASSERT_LEVEL | 描述 | 函数 | 函数状态 |
|---|---|---|---|
| 0 | 关闭全部断言 | SDL_assert SDL_assert_release SDL_assert_paranoid | disabled disabled disabled |
| 1 | 为了正式版本(默认) | SDL_assert SDL_assert_release SDL_assert_paranoid | disabled enabled disabled |
| 2 | 调试版本 | SDL_assert SDL_assert_release SDL_assert_paranoid | enabled enabled disabled |
| 3 | 打开全部检查 | SDL_assert SDL_assert_release SDL_assert_paranoid | enabled enabled enabled |
可以使用的断言
void SDL_assert(condition);
void SDL_assert_paranoid(condition);
void SDL_assert_release(condition);
SDL错误处理
使用下面三个函数
int SDL_SetError(const char* fmt, ...);
const char* SDL_GetError(void);
void SDL_ClearError(void);
下面有些例子
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
// Unrecoverable error, exit here.
printf("SDL_Init failed: %s\n", SDL_GetError());
}
int errorCode = 0;
...
errorCode = -37;
...
if (errorCode < 0)
SDL_SetError("Something unexpected happened: Error Code %d", errorCode);
使用SDL的错误处理与断言技巧

本文介绍了SDL库中关于错误处理的机制,特别是SDL_ASSERT_LEVEL如何控制不同断言的激活。内容涵盖可选的断言级别及其影响,以及SDL错误处理的常用函数,通过实例展示了如何有效地运用这些功能。
3万+

被折叠的 条评论
为什么被折叠?



