#5
by みけCAT » 5年前
ちなみに、今回は追加した仮ソースコードを以下のように変更することで、
一部の関数の呼び出しのログを取り、異常な描画関数の呼び出しを発見しました。
ALL.h
コード:
#ifndef ALL_H_GUARD_BE6CB1AC_7161_4AE9_9B9E_748D0EEC3A87
#define ALL_H_GUARD_BE6CB1AC_7161_4AE9_9B9E_748D0EEC3A87
#include <DxLib.h>
#include "Loading.h"
#include "PL_Shot.h"
static const int SCREEN_WIDTH = 1280;
void PlayerInit();
void PlayerUpdate();
extern int count, playerImgIndex, timer, WaitAnimTimer;
struct coord {
int x, y;
};
struct OBJ2D {
int exist, mvAlg, dir;
coord pos, speed;
};
int DrawGraph_check(int x, int y, int g, int f);
#define DrawGraph DrawGraph_check
int ScreenFlip_check();
#define ScreenFlip ScreenFlip_check
int ClearDrawScreen_check();
#define ClearDrawScreen ClearDrawScreen_check
#endif
haribote.cpp
コード:
#include "All.h"
#include <stdio.h>
#undef DrawGraph
#undef ScreenFlip
#undef ClearDrawScreen
Handle handle;
FILE* fp;
void load() {
LoadDivGraph("Player.png", 40, 8, 5, 32, 32, handle.image.Player);
LoadDivGraph("PL_Shot.png", 5, 5, 1, 32, 32, handle.image.PL_Shot);
LoadDivGraph("PL_Shot2.png", 5, 5, 1, 32, 32, handle.image.PL_Shot2);
handle.image.prot = LoadGraph("prot.png");
fp = fopen("debug_log.txt", "w");
}
int DrawGraph_check(int x, int y, int g, int f) {
if (fp != NULL) {
fprintf(fp, "DrawGraph(%d, %d, %d, %d)\n", x, y, g, f);
fflush(fp);
}
return DrawGraph(x, y, g, f);
}
int ScreenFlip_check() {
if (fp != NULL) {
fputs("ScreenFlip()\n", fp);
fflush(fp);
}
return ScreenFlip();
}
int ClearDrawScreen_check() {
if (fp != NULL) {
fputs("ClearDrawScreen()\n", fp);
fflush(fp);
}
return ClearDrawScreen();
}
取得されたログの一部 (描画関数が異常に何度も呼ばれ、x座標が順に更新されていることがわかる)
コード:
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(444, 656, 70713395, 1)
DrawGraph(244, 656, 70713395, 1)
DrawGraph(444, 656, 70713395, 1)
DrawGraph(264, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(464, 656, 70713395, 1)
DrawGraph(264, 656, 70713395, 1)
DrawGraph(464, 656, 70713395, 1)
DrawGraph(284, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(284, 656, 70713395, 1)
DrawGraph(84, 656, 70713395, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(84, 656, 70713395, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(324, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(324, 656, 70713395, 1)
DrawGraph(124, 656, 70713395, 1)
ScreenFlip()
ちなみに、今回は追加した仮ソースコードを以下のように変更することで、
一部の関数の呼び出しのログを取り、異常な描画関数の呼び出しを発見しました。
ALL.h
[code]
#ifndef ALL_H_GUARD_BE6CB1AC_7161_4AE9_9B9E_748D0EEC3A87
#define ALL_H_GUARD_BE6CB1AC_7161_4AE9_9B9E_748D0EEC3A87
#include <DxLib.h>
#include "Loading.h"
#include "PL_Shot.h"
static const int SCREEN_WIDTH = 1280;
void PlayerInit();
void PlayerUpdate();
extern int count, playerImgIndex, timer, WaitAnimTimer;
struct coord {
int x, y;
};
struct OBJ2D {
int exist, mvAlg, dir;
coord pos, speed;
};
int DrawGraph_check(int x, int y, int g, int f);
#define DrawGraph DrawGraph_check
int ScreenFlip_check();
#define ScreenFlip ScreenFlip_check
int ClearDrawScreen_check();
#define ClearDrawScreen ClearDrawScreen_check
#endif
[/code]
haribote.cpp
[code]
#include "All.h"
#include <stdio.h>
#undef DrawGraph
#undef ScreenFlip
#undef ClearDrawScreen
Handle handle;
FILE* fp;
void load() {
LoadDivGraph("Player.png", 40, 8, 5, 32, 32, handle.image.Player);
LoadDivGraph("PL_Shot.png", 5, 5, 1, 32, 32, handle.image.PL_Shot);
LoadDivGraph("PL_Shot2.png", 5, 5, 1, 32, 32, handle.image.PL_Shot2);
handle.image.prot = LoadGraph("prot.png");
fp = fopen("debug_log.txt", "w");
}
int DrawGraph_check(int x, int y, int g, int f) {
if (fp != NULL) {
fprintf(fp, "DrawGraph(%d, %d, %d, %d)\n", x, y, g, f);
fflush(fp);
}
return DrawGraph(x, y, g, f);
}
int ScreenFlip_check() {
if (fp != NULL) {
fputs("ScreenFlip()\n", fp);
fflush(fp);
}
return ScreenFlip();
}
int ClearDrawScreen_check() {
if (fp != NULL) {
fputs("ClearDrawScreen()\n", fp);
fflush(fp);
}
return ClearDrawScreen();
}
[/code]
取得されたログの一部 (描画関数が異常に何度も呼ばれ、x座標が順に更新されていることがわかる)
[code]
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(444, 656, 70713395, 1)
DrawGraph(244, 656, 70713395, 1)
DrawGraph(444, 656, 70713395, 1)
DrawGraph(264, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(464, 656, 70713395, 1)
DrawGraph(264, 656, 70713395, 1)
DrawGraph(464, 656, 70713395, 1)
DrawGraph(284, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(284, 656, 70713395, 1)
DrawGraph(84, 656, 70713395, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(84, 656, 70713395, 1)
DrawGraph(484, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
ScreenFlip()
ClearDrawScreen()
DrawGraph(0, 592, 67436548, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(304, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(324, 656, 70713395, 1)
DrawGraph(104, 656, 70713395, 1)
DrawGraph(504, 656, 70713395, 1)
DrawGraph(324, 656, 70713395, 1)
DrawGraph(124, 656, 70713395, 1)
ScreenFlip()
[/code]