"Frame not in module" 使用 glTexImage2D 时

"Frame not in module" when using glTexImage2D

我以前从未遇到过这个错误,我在项目的其他地方使用 glTexImage2D 没有错误。下面是错误 Visual Studio 显示的屏幕截图,以及反汇编视图:

鉴于该行中有 ptr,我假设存在指针错误,但我不知道我做错了什么。 下面是我用来从 SDL_surface 转换为纹理的函数。

void surfaceToTexture(SDL_Surface *&surface, GLuint &texture) {
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels);
    glDisable(GL_TEXTURE_2D);
}

此函数在程序的其他地方成功,例如加载文本时:

SDL_Surface *surface; 
surface = TTF_RenderText_Blended(tempFont, message.c_str(), color);
if (surface == NULL)
    printf("Unable to generate text surface using font: %s! SDL_ttf Error: %s\n", font.c_str(), TTF_GetError());
else {
    SDL_LockSurface(surface);
    width = surface->w;
    height = surface->h;
    if (style != TTF_STYLE_NORMAL)
        TTF_SetFontStyle(tempFont, TTF_STYLE_NORMAL);
    surfaceToTexture(surface, texture);
    SDL_UnlockSurface(surface);
}
SDL_FreeSurface(surface);

但加载图像时不是:

SDL_Surface* surface = IMG_Load(path.c_str());
if (surface == NULL)
    printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
else{
    SDL_LockSurface(surface);
    width = (w==0)?surface->w:w;
    height = (h==0)?surface->h/4:h;
    surfaceToTexture(surface, texture);
    SDL_UnlockSurface(surface);
}
SDL_FreeSurface(surface);

这两个例子都是从 class 中提取的,其中定义了 texture。 图片路径正确。 我知道是 glTexImage2D 导致了问题,因为我在 surfaceToTexture 的开头添加了一个断点并单步执行了该函数。 即使它不起作用,texturesurface 看起来确实是正确的 values/properties.

有什么想法吗?

您得到的错误意味着,进程在一段代码内崩溃,调试器找不到任何调试信息(汇编和源代码之间的关联)。 a/your 程序的调试构建中的任何内容通常都是这种情况。

现在,在您的情况下,您调用 glTexImage2D 时使用的参数 "lie" 是关于您使用 data 参数指向的缓冲区的内存布局.指针不携带任何有意义的元信息(就汇编级别而言,它们只是另一个具有特殊含义的整数)。所以你必须确保你传递给函数的所有参数和指针都匹配。如果不是,那么在该函数的深处某处,或者它调用的任何东西(或那个调用等),内存的访问方式可能会违反操作系统设置的约束,从而引发那种崩溃。

您的问题的解决方案:修复您的代码,即确保您传递给 OpenGL 的内容是一致的。它在 OpenGL 驱动程序中崩溃,但只是因为你对它撒了谎。