C++ SDL,为什么 SDL_LoadBMP() 返回 NULL? [英] C++ SDL, why does SDL_LoadBMP() return NULL?

查看:61
本文介绍了C++ SDL,为什么 SDL_LoadBMP() 返回 NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做了一些研究后才开始使用 SDL.我从本教程开始http://lazyfoo.net/SDL_tutorials/lesson01/index2.php <<使用完全相同的代码和 bmp 图像.

I've just started with SDL after doing some research. I started with this tutorial http://lazyfoo.net/SDL_tutorials/lesson01/index2.php << Using the exact same code and bmp image.

出于某种原因,当我在 IDE(Microsoft Visual Studio)中调试和运行程序时,屏幕会加载,但应该在屏幕上弹出的图片却没有.但是,当我进入我的项目并手动运行程序时,它会顺利完成所有工作.经过一些研究,结果证明 SDL_LoadBMP() 返回 NULL(如果发生错误,它返回 NULL).但为什么?另外,我如何才能看到错误实际上是什么?

For some reason when I debug and run the program inside my IDE (Microsoft visual studio) the screen loads but the picture that should be popping up on the screen does not. However, when I would go to my project and run the program manually it does everything smoothly. After doing some research it turned out SDL_LoadBMP() returns NULL (it returns NULL if an error occured). But why? Also, how can I see what the error actually is?

推荐答案

您尝试加载的位图是否在正确的目录中?当你从 Visual Studio 启动你的程序时,它从你的项目(.vcproj.vcxproj 文件)所在目录中的当前工作目录开始.确保您的路径都相对于该目录.

Is the bitmap you're trying to load in the correct directory? When you launch your program from Visual Studio, it starts with the current working directory in the directory where your project (.vcproj or .vcxproj file) is contained. Make sure your paths are all relative to that directory.

但是,如果您通过双击 Windows 资源管理器中的可执行文件(默认情况下通常位于 Debug\Release\ 子目录中)启动,则它从该文件夹的当前工作目录开始.

However, if you're launching by double-clicking the executable in Windows Explorer (which is typically in a Debug\ or Release\ subdirectory by default), then it starts with a current working directory of that folder.

这篇关于C++ SDL,为什么 SDL_LoadBMP() 返回 NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆