2016-04-10 17 views
0

私はsdlを初めて使用しています。私はブラックジャックゲームを作る過程にある。私はテクスチャの配列を作りたいと思います。誰かが私を助けることができるのだろうかと思っていました。ここで私がやろうとしてきたものです: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と呼ばれている)私はコード内で上に示され、このエラーが発生します。0x6C78CE9A(SDL2で

未処理の例外。 dll)introSDL.exe:0xC0000005:アクセス違反は、場所0x00000050を読み取っています。

答えて

2

あなたの配列の境界から書き出しています。

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]])); 
+0

返信いただきありがとうございます。あなたが言っていることは意味をなさないが、今はintroSDL.exeの0x779DDAD8に未処理の例外が発生している:Microsoft C++例外:メモリ位置0x0018EFE4のstd :: bad_allocがhitCardsText.push_back(loadTexture(ren、cards [dynamicPlayerCards [0]) )); – soso

関連する問題