问题描述
我花了最后一个小时来尝试解决此错误。我已经在SO和其他站点的各处搜索了答案,但是到目前为止,我所发现的任何方法都无效。所以在这里,我迫切需要帮助。
首先是我正在使用的软件和库的版本:
- SDL2-2.0.12
- SDL2_image-2.0.5
- VS社区2019
这是我弄乱区域的代码:
bool CApp::OnInit() {
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL Could not initialize! SDL_Error: %s\n",SDL_GetError());
return false;
}
else {
std::cout << "SDL was initialized!!!" << std::endl;
}
// The window for the game.
Surf_Window = SDL_CreateWindow("SDL2 Window",SDL_WINDOWPOS_CENTERED,screenWidth,screenHeight,0);
if (Surf_Window == NULL)
{
return false;
}
else {
std::cout << "Main Window was initialized!!!" << std::endl;
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags))
{
printf("SDL_image Could not initialize! SDL_image Error: %s\n",IMG_GetError());
return false;
}
else
{
std::cout << "SDL_image was initialized!!!" << std::endl;
//Get window surface
Surf_display = SDL_GetwindowSurface(Surf_Window);
if (Surf_display == NULL)
{
return false;
}
}
}
// Fill the window with White color.
SDL_FillRect(Surf_display,NULL,SDL_MapRGB(Surf_display->format,0xFF,0xFF));
// The image surface we load.
const char* image = "data/images/bgHomeScreen.bmp";
Surf_Test = CApp::OnLoad("data/images/bgHomeScreen.bmp");
//CSurface::OnLoad(Surf_Test,image);
if (Surf_Test == NULL)
{
printf("Unable to load image %s! SDL Error: %s\n","data/images/bgHomeScreen.bmp",SDL_GetError());
return false;
}
SDL_UpdateWindowSurface(Surf_Window);
SDL_Delay(2000);
return true;
}
解决方法
我发现了问题所在。我将SDL2-2.0.12\lib\x86
的所有依赖项添加到我的项目的Release和Debug目录中,程序按预期运行。如果计划使用64位,请记住要复制x64文件夹而不是x86。