#include "DxLib.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
char* FileName= "Data\\testEffect.txt";
int id;
char*Str;
LONGLONG size;
SetUseASyncLoadFlag(FALSE);
id = FileRead_open(FileName);
if (id == -1) {
FileRead_close(id);
DxLib_End();
return 0;
}
size = FileRead_size(FileName);
printfDx("(%d,%d)\n",id,size);
Str = (char*)malloc(size + 1);
int count=0;
SetUseASyncLoadFlag(TRUE);
bool is_flag=false;
while (ProcessMessage() == 0 && ClearDrawScreen() == 0){
if(is_flag==false){
FileRead_read(Str, size, id);
if (CheckHandleASyncLoad(id) == -1)printfDx("error");
if (CheckHandleASyncLoad(id) == FALSE) {
Str[size] = '\0';
printfDx(Str);
is_flag=true;
FileRead_close(id);
free(Str);
Str=nullptr;
}
count++;
}
DrawFormatString(100, 100, GetColor(255, 255, 255), "%d", count);
ScreenFlip();
}
if (Str != nullptr) {
FileRead_close(id);
free(Str);
}
DxLib_End();
return 0;
}
以上のコードで非同期読み込みを行うと終わらないことがあります。
厄介なことに成功することもあるので、ファイルが存在しないというとはないと思います。
Debug、Releaseともに失敗しますが、Releaseだと成功したことがありません。
#include "DxLib.h"
#include <malloc.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
char* FileName= "Data\\testEffect.txt";
int id;
char*Str;
LONGLONG size;
int heapstatus;
SetUseASyncLoadFlag(FALSE);
id = FileRead_open(FileName);
if (id == -1) {
FileRead_close(id);
DxLib_End();
return 0;
}
size = FileRead_size(FileName);
printfDx("(%d,%d)\n",id,size);
Str = (char*)malloc(size + 1);
int count=0;
SetUseASyncLoadFlag(TRUE);
bool is_flag=false;
while (ProcessMessage() == 0 && ClearDrawScreen() == 0){
clsDx();
if(is_flag==false){
heapstatus = _heapchk();
switch (heapstatus) {
case _HEAPOK:
printfDx(" OK - heap is fine\n");
break;
case _HEAPEMPTY:
printfDx(" OK - heap is empty\n");
break;
case _HEAPBADBEGIN:
printfDx("ERROR - bad start of heap\n");
break;
case _HEAPBADNODE:
printfDx("ERROR - bad node in heap\n");
break;
}
FileRead_read(Str, size, id);
if (CheckHandleASyncLoad(id) == -1)printfDx("error");
if (CheckHandleASyncLoad(id) == FALSE) {
Str[size] = '\0';
printfDx(Str);
is_flag=true;
FileRead_close(id);
free(Str);
Str=nullptr;
}
count++;
}
DrawFormatString(100, 100, GetColor(255, 255, 255), "%d", count);
ScreenFlip();
}
if (Str != nullptr) {
FileRead_close(id);
free(Str);
}
DxLib_End();
return 0;
}
一体何が原因なんでしょうか?
管理者として実行、互換モード(window 7)で実行も試してみましたが駄目でした。