SDL 纹理数组?
SDL texture array?
我是 sdl 的新手。我正在制作二十一点游戏。我想制作一系列纹理。我想知道是否有人能够帮助我。这是我一直在尝试做的事情:
// array of textures for the extra player cards
SDL_Texture *hitCardsText[] = { NULL };
// this does not give me errors but i dont know if it is right
hitCardsText[0] = loadTexture(ren, cards[dynamicPlayerCards[0]]);
hitCardsText[1] = loadTexture(ren, cards[dynamicPlayerCards[1]]);
// i get an error here
SDL_DestroyTexture(hitCardsText[0]);
SDL_DestroyTexture(hitCardsText[1]);
我在上面的代码中指出了这个错误(我的文件名为 introSDL.exe 顺便说一句):
introSDL.exe 中 0x6C78CE9A (SDL2.dll) 的未处理异常:0xC0000005:读取位置 0x00000050 的访问冲突。
您写的越界了。
SDL_Texture *hitCardsText[] = { NULL };
只有 1 个元素。如果您想要更多,您要么需要向初始化列表添加更多元素,要么在方括号中指定确切数量。
如果你想要一个动态大小的数组,那么使用std::vector
。
std::vector<SDL_Texture*> hitCardsText;
hitCardsText.push_back(loadTexture(ren, cards[dynamicPlayerCards[0]]));
hitCardsText.push_back(loadTexture(ren, cards[dynamicPlayerCards[1]]));
我是 sdl 的新手。我正在制作二十一点游戏。我想制作一系列纹理。我想知道是否有人能够帮助我。这是我一直在尝试做的事情:
// array of textures for the extra player cards
SDL_Texture *hitCardsText[] = { NULL };
// this does not give me errors but i dont know if it is right
hitCardsText[0] = loadTexture(ren, cards[dynamicPlayerCards[0]]);
hitCardsText[1] = loadTexture(ren, cards[dynamicPlayerCards[1]]);
// i get an error here
SDL_DestroyTexture(hitCardsText[0]);
SDL_DestroyTexture(hitCardsText[1]);
我在上面的代码中指出了这个错误(我的文件名为 introSDL.exe 顺便说一句):
introSDL.exe 中 0x6C78CE9A (SDL2.dll) 的未处理异常:0xC0000005:读取位置 0x00000050 的访问冲突。
您写的越界了。
SDL_Texture *hitCardsText[] = { NULL };
只有 1 个元素。如果您想要更多,您要么需要向初始化列表添加更多元素,要么在方括号中指定确切数量。
如果你想要一个动态大小的数组,那么使用std::vector
。
std::vector<SDL_Texture*> hitCardsText;
hitCardsText.push_back(loadTexture(ren, cards[dynamicPlayerCards[0]]));
hitCardsText.push_back(loadTexture(ren, cards[dynamicPlayerCards[1]]));