Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;OpenGL/SDL 2.0加载纹理失败_C++_Opengl_Textures_Loading_Sdl 2 - Fatal编程技术网

C++ C++;OpenGL/SDL 2.0加载纹理失败

C++ C++;OpenGL/SDL 2.0加载纹理失败,c++,opengl,textures,loading,sdl-2,C++,Opengl,Textures,Loading,Sdl 2,如果尝试加载纹理,则会出现以下错误: Access violation reading location. Unhandled exception at 0x651B5A17 (nvcuda.dll) in nsighttest.exe: 0xC0000005: Access violation reading location 0x00000010. 图片: 调试映像: unsigned int loadTexture(const char*filename,texProperties

如果尝试加载纹理,则会出现以下错误:

Access violation reading location.
Unhandled exception at 0x651B5A17 (nvcuda.dll) in nsighttest.exe: 0xC0000005: Access  violation reading location 0x00000010.
图片:

调试映像:

unsigned int loadTexture(const char*filename,texProperties)
{
闪烁数=0;
盂型;
SDL_表面*img=img_载荷(文件名);

cout查看glTexImage2D()函数,看起来您正在使用
img->w
两次,而不是第二次使用
img->h

试着打电话

glTexImage2D(GL_TEXTURE_2D, 0 , numberofcolors=4?GL_RGBA:GL_RGB, img->w, /*Use height as second parameter, rather than width!*/img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);

相反。

你为什么不检查
SDL\u LoadBMP()
的返回值,或者验证你要返回的
SDL\u曲面实际上是
GL\u UNSIGNED\u SHORT\u 5\u 6\u 5
?我已经检查了返回值,但我得到了一些数字,并尝试使用“GL\u UNSIGNED\u SHORT\u 5\u 6\u 5”同样的结果也会让人猜测,与99%的图像问题一样,它没有加载,因为它位于错误的位置或其他地方。您需要检查
SDL\u Surface*img
是否为有效的内存位置,即在使用带三个通道的24位BMP之后,不为空。
glTexImage2D(GL_TEXTURE_2D, 0 , numberofcolors=4?GL_RGBA:GL_RGB, img->w, /*Use height as second parameter, rather than width!*/img->h, 0, format, GL_UNSIGNED_BYTE, img->pixels);