【发布时间】:2013-05-02 16:47:20
【问题描述】:
我在使用 Visual Studio 2012 时遇到了一个恼人的访问冲突问题。我在 Visual Studio 2010 中遇到了同样的问题,我认为这可能是编译器问题,但事实证明并非如此。
这是导致访问冲突的部分代码:
SDL_Surface *cGraphicsManager::LoadImageFromPak(char *filename, char *img_type)
{
// Load the 'file' to SDL_Surface
SDL_Surface *img = NULL;
char errorname[50];
sprintf(errorname, "Unable to load image %s from pakfile", filename);
FILE *fin = pakfile.open_file(filename);
if(!fin)
{
ErrorLog(errorname);
return NULL;
}
SDL_RWops *rw;
rw = SDL_RWFromFP(fin, 1);
if (!rw)
{
ErrorLog("Erro na linha 213");
return NULL;
}
img = IMG_LoadTyped_RW(rw,0, img_type); // it crashes on this line
if(img == NULL)
ErrorLog("Unable to load image from pakfile.");
SDL_FreeRW(rw);
//pakfile.close_mpk();
//if (img_type == "PNG")
img = add_transparency(img);
return img;
}
它让我在位置 0x00000014 写入访问冲突。 奇怪的是它在 MingW 编译器上编译并运行良好,这让我认为这不是错误的代码。 我读到了一些关于 File* 和 Dll 调用问题的文章,但我没有找到解决方法。 我没有链接警告,我已经链接了所有必要的库。我也在调试模式下运行它并在多线程调试 dll (MDd) 中编译。 与 MingW 相比,Visual Studio 编写代码的速度更快,调试也更容易,我将不胜感激。 非常感谢。
【问题讨论】:
-
好的,那么是哪一行代码产生了异常???
-
如果你真的使用 C++ 而不是 C 的类,你可能会遇到更少的麻烦。
-
崩溃时
img_type的值是多少? -
@OldProgrammer OP 注意到他的示例中的崩溃行
标签: c++