visual c++和SDL-访问冲突错误
visual c++ and SDL- Access violation error
我需要你的帮助。我整天都在想我为什么会犯这个错误,但我什么都没想到。我想让我的程序做的事情是拍摄一个png图像并将其切片成瓷砖,我可以稍后用来制作地图。那么,有人能帮我解决这个错误吗?
#include "SDL.h"
#include "SDL_image.h"
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL_image.lib")
int main(int argc,char *argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
IMG_Init(IMG_INIT_PNG);
SDL_Surface *mapTileSet;
mapTileSet = IMG_Load("map.png");
SDL_Surface *myTiles[4];
for(int i = 0; i < 3; i++)
myTiles[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCCOLORKEY, 32, 32, 32, 0, 0, 0, 0);
for(int y = 0; y < 3; y++)
{
for(int x = 0; x < 3; x++)
{
int slice_x = x * 32;
int slice_y = y * 32;
SDL_Rect srcRect;
srcRect.x = slice_x;
srcRect.y = slice_y;
srcRect.w = 32;
srcRect.h = 32;
SDL_Rect dstRect;
dstRect.x = 0;
dstRect.y = 0;
int i = x + y * 4;
SDL_BlitSurface(mapTileSet, &srcRect, myTiles[i], &dstRect);
}
}
SDL_BlitSurface(myTiles[0], 0, screen, 0);
SDL_Flip(screen);
SDL_Delay(10000);
IMG_Quit();
SDL_Quit();
return 0;
}
调试日志:
'project.exe': Loaded 'C:UsersRokasDesktopThe GameThe GameDebugproject.exe', Symbols loaded.
'project.exe': Loaded 'C:WindowsSystem32ntdll.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32kernel32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32KernelBase.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:Program FilesAVAST SoftwareAvastsnxhk.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:UsersRokasDesktopThe GameThe GameSDL.dll', Binary was not built with debug information.
'project.exe': Loaded 'C:WindowsSystem32advapi32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32msvcrt.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32sechost.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32rpcrt4.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32gdi32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32user32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32lpk.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32usp10.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32winmm.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:UsersRokasDesktopThe GameThe GameSDL_image.dll', Binary was not built with debug information.
'project.exe': Loaded 'C:WindowsSystem32msvcr100d.dll', Symbols loaded.
'project.exe': Loaded 'C:WindowsSystem32imm32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32msctf.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32ddraw.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32dciman32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32setupapi.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32cfgmgr32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32oleaut32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32ole32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32devobj.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32dwmapi.dll', Cannot find or open the PDB file
'project.exe': Unloaded 'C:WindowsSystem32ddraw.dll'
'project.exe': Unloaded 'C:WindowsSystem32dwmapi.dll'
'project.exe': Unloaded 'C:WindowsSystem32setupapi.dll'
'project.exe': Unloaded 'C:WindowsSystem32devobj.dll'
'project.exe': Unloaded 'C:WindowsSystem32oleaut32.dll'
'project.exe': Unloaded 'C:WindowsSystem32ole32.dll'
'project.exe': Unloaded 'C:WindowsSystem32cfgmgr32.dll'
'project.exe': Unloaded 'C:WindowsSystem32dciman32.dll'
'project.exe': Loaded 'C:WindowsSystem32uxtheme.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32dwmapi.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32KBDUS.DLL', Cannot find or open the PDB file
'project.exe': Unloaded 'C:WindowsSystem32KBDUS.DLL'
'project.exe': Loaded 'C:WindowsSystem32KBDUS.DLL', Cannot find or open the PDB file
'project.exe': Unloaded 'C:WindowsSystem32KBDUS.DLL'
'project.exe': Loaded 'C:WindowsSystem32dsound.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32ole32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32powrprof.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32setupapi.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32cfgmgr32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32oleaut32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32devobj.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32dinput.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32hid.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32wintrust.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32crypt32.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32msasn1.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:WindowsSystem32cryptbase.dll', Cannot find or open the PDB file
'project.exe': Loaded 'C:UsersRokasDesktopThe GameThe Gamelibpng15-15.dll', Binary was not built with debug information.
'project.exe': Loaded 'C:UsersRokasDesktopThe GameThe Gamezlib1.dll', Binary was not built with debug information.
First-chance exception at 0x681247e3 in project.exe: 0xC0000005: Access violation reading location 0xccccccf8.
Unhandled exception at 0x681247e3 in project.exe: 0xC0000005: Access violation reading location 0xccccccf8.
The thread 'Win32 Thread' (0xd94) has exited with code -805306369 (0xcfffffff).
The thread 'Win32 Thread' (0x12f8) has exited with code -805306369 (0xcfffffff).
The program '[3568] project.exe: Native' has exited with code -805306369 (0xcfffffff).
您正在创建这样的瓦片:
for(int i = 0; i < 3; i++)
myTiles[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCCOLORKEY, 32, 32, 32, 0, 0, 0, 0);
其中i将等于0、1和2
但是这样访问它们:
int i = x + y * 4;
SDL_BlitSurface(mapTileSet, &srcRect, myTiles[i], &dstRect);
其中x和y分别为0、1和2。一旦y大于0,您将访问无效数据。
通常,对于包含的循环,i=x+y*4语句似乎格式错误,因为它将生成省略元素3和7的序列{0,1,2,4,5,6,8,9,10}。
相关文章:
- 使用 EvtSetChannelConfigProperty() 函数时出现访问冲突错误
- cv::resize() 失败并出现访问冲突错误(由 NULL> 处的 <struct 引起)
- 将 std::string 作为参数从一个 DLL 传递到另一个 DLL 引发访问冲突错误
- 遵循官方 Direct2D 示例,但出现访问冲突错误
- C++ 抛出读取访问冲突错误,但我不确定为什么。平铺滑块益智游戏
- 为什么我的顶点缓冲区对象出现访问冲突错误?
- 销毁 Box2D 主体 - 读取访问冲突错误
- 编译哈希算法时出现内存访问冲突错误
- 使用glCreateBuffers时发生访问冲突错误
- 访问冲突错误在 (而 (info[x] != ))
- 反转字符串 c++ 时出现访问冲突错误
- 我无法弄清楚此访问冲突错误.有人可以在这里帮助我吗?
- 使用内存访问冲突错误
- 读取字符串的字符时出错-访问冲突错误C++
- 创建链接列表时发生访问冲突错误
- 调试优先级队列程序时出现访问冲突错误
- C++LinkedList错误:访问冲突错误
- 为什么我在用SDL2_ttf填充文本时出现访问冲突错误
- MFC:在工作线程中使用对象的成员函数时获取访问冲突错误
- 在C++中使用Box2D物理退出游戏时出现访问冲突错误