c++ - 从 Visual Studio 运行时,基本 C++ SDL 程序抛出异常 0xC0000005
问题描述
使用 SDL 2.0.14,我编写了一个基本的 main 函数,创建一个空窗口并在 SDL_QUIT 事件时关闭它。从我正在使用的 Visual Studio 2019 IDE(x64 平台,调试和发布模式)运行时,程序在窗口关闭时运行良好;然后 IDE 生成以下消息:
Exception thrown at 0x00007FFBFAE55BB6 (ntdll.dll) in my_program.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFBEA2000F.
它还指向 exe_common.inl 文件中的代码。编译后的可执行文件运行时没有任何明显的问题。
我的程序的单一源文件包含以下内容:
#include <iostream>
#include <SDL.h>
int main(int argc, char* args[]){
const int window_width{ 800 };
const int window_height{ 600 };
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << "SDL init failed" << std::endl;
return 1;
}
SDL_Window* window = SDL_CreateWindow(
"My Program",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
window_width,
window_height,
SDL_WINDOW_SHOWN);
if (!window) {
SDL_Quit();
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 2;
}
bool quit = false;
SDL_Event event;
while (!quit) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
解决方案
推荐阅读
- spring - 更改 Spring Reactive MongoDB 的排序规则
- c# - 如何删除选项卡标题并拉伸 TabControl 以便不显示空白?
- c# - 检测链接是否为可下载文件
- r - 如何在 Rstudio (stargazer) 中创建具有描述性统计的表?
- laravel - 如何在 Laravel Mix 中使用 purgeCss
- sql - 在 where 子句中唯一
- libreoffice - 当我选择表格 [Libreoffice] 时,无法点击 PDF 导出时的目录链接
- python - matplotlib 中的逐步线图
- docker - 什么是“清单 blob 未知:注册表未知的 blob”错误
- python - (没有名为 __main__ 的模块)在 bashrc 中使用别名时