Stack around the variable 'graph_cards' was corruptedというデバッグ

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら

トピックに返信する


答えを正確にご入力ください。答えられるかどうかでスパムボットか否かを判定します。

BBCode: ON
[img]: ON
[flash]: OFF
[url]: ON
スマイリー: OFF

トピックのレビュー
   

展開ビュー トピックのレビュー: Stack around the variable 'graph_cards' was corruptedというデバッグ

Re: Stack around the variable 'graph_cards' was corruptedという

#4

by aaaa » 7年前

ありがとうございます!
無事出来ました!

Re: Stack around the variable 'graph_cards' was corruptedという

#3

by かずま » 7年前

int graph_marks[2] に
LoadDivGraph("mark.png", 4, 4, 1, 28, 28, graph_marks); で
グラフィックハンドルを 4個格納すると、場所が 2個しかないので、
隣の変数である graph_cards[2] を壊しているということでしょう。

Re: Stack around the variable 'graph_cards' was corruptedという

#2

by purin52002 » 7年前

Stack around the variable 'graph_cards' was corrupted
直訳すると「変数'graph_cards'周りのスタックが破壊された」ですかね?

graph_cardsは配列のようですし、おそらく範囲外へのアクセスのせいじゃないでしょうか。
んで、graph_cardsを使っているのが
DrawGraph(x2, y2, graph_cards[cards[y][x].reverse], FALSE);

cards[y][x].reverseに何が入っているのかなー、と考えるとbool型のデータみたいですね。
ここからは私の体験談なので、詳しくは自分で調べていただきたいのですが、
bool型の変数には「0か0以外」の数値が入るようです。(私がデバッグの時に出力された数字は12)
おそらくこのせいではないでしょうか?

Stack around the variable 'graph_cards' was corruptedというデバッグ

#1

by aaaa » 7年前

コード:

#include "DxLib.h"

// 場のカードデータ
struct {
	int mark;
	int number;
	bool reverse;
} cards[3][4];

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	int turns = 0;
	int ox, oy, nx, ny;
	int remains = 12;
	int start_time, elapsed_time;
	bool mouse_flag = false;
	int graph_cards[2], graph_marks[2], graph_numbers[6];
	ChangeWindowMode(TRUE);
	DxLib_Init();
	SetDrawScreen(DX_SCREEN_BACK);
	LoadDivGraph("card.png", 2, 2, 1, 40, 64, graph_cards);
	LoadDivGraph("mark.png", 4, 4, 1, 28, 28, graph_marks);
	LoadDivGraph("number.png", 6, 6, 1, 28, 28, graph_numbers);
	// シャッフル
	bool deal[3][4] = {};
	for (int mk = 0; mk < 2; mk++)
	{
		for (int no = 0; no < 3; no++)
		{
			for (int i = 0; i < 2; i++)
			{
				int x, y;
				do { x = GetRand(3); y = GetRand(2); } while (deal[y][x]);
				cards[y][x].mark = mk;
				cards[y][x].number = no;
				cards[y][x].reverse = true;
				deal[y][x] = true;
			}
		}
	}
	start_time = GetNowCount();
	while (!ProcessMessage()) {
		ClearDrawScreen();
		// カードめくり処理
		if (GetMouseInput() & MOUSE_INPUT_LEFT) {
			if (!mouse_flag) {
				mouse_flag = true;
				if (turns == 2) {
					cards[oy][ox].reverse = true;
					cards[ny][nx].reverse = true;
					turns = 0;
				}
				else {
					GetMousePoint(&nx, &ny);
					nx = (nx - 222) / 40;
					ny = (ny - 148) / 64;
					if (nx >= 0 && nx <= 3 && ny >= 0 && ny <= 2 && cards[ny][nx].reverse) {
						cards[ny][nx].reverse = false;
						if (turns == 0) {
							ox = nx; oy = ny;
							turns = 1;
						}
						else {
							if (cards[ny][nx].number == cards[oy][ox].number) {
								remains -= 2;
								turns = 0;
							}
							else turns = 2;
						}
					}
				}
			}
		}
		else mouse_flag = false;
		// 場のカード表示
		for (int y = 0; y < 3; y++) for (int x = 0; x < 4; x++) {
			int x2 = x * 40 + 225;
			int y2 = y * 64 + 125;
			DrawGraph(x2, y2, graph_cards[cards[y][x].reverse], FALSE);
			if (!cards[y][x].reverse) {
				DrawGraph(x2 + 6, y2 + 5, graph_marks[cards[y][x].mark], FALSE);
				DrawGraph(x2 + 6, y2 + 32, graph_numbers[cards[y][x].number], FALSE);
			}
		}
		// メッセージ表示
		int color = GetColor(255, 255, 255);
		if (remains <= 0) DrawString(8, 8, "クリア!", color);
		else elapsed_time = (GetNowCount() - start_time) / 1000;
		DrawFormatString(8, 450, color, "残り %d枚  経過時間 %d秒", remains, elapsed_time);
		ScreenFlip();
	}
	DxLib_End();
}
このプログラムをdxlibで実行すると、Stack around the variable 'graph_cards' was corruptedというデバッグエラーがでます。
どうしてですか?

ページトップ