0

私はVisual Studio 2013のゲームエンジンで作業していますが、FreeImage v3.17ライブラリを使用しようとしましたが、lib自体によって提供される簡単な例でライブラリを使用しようとすると、プログラムは次のようになります。ビルドディレクトリから直接実行しない限り、イメージをロードできません。私はまた、異なるソフトウェアによって作成された異なるフォーマットの画像をテストしました。Visual Studio 2013デバッガでFreeImageライブラリが動作しませんか?

具体的には、コードをステップ実行すると、FreeImageはファイルタイプをFreeImage_GetFIFFromFilename()(つまりfif == FIF_PNGなど)から正しく推定しているようです。その後、FreeImage_FIFSupportsReading(fif)の呼び出しはtrueを返し、dibを割り当てようとしますが、FreeImage_Load()は常にNULLを返します。

// >とのコメントを参照してください:私はVSのデバッガでプログラムを実行すると、私の疑いが何とかデバッグヒープが故障しているということですので、

int main(int argc, char ** argv) 
{ 
    const char* filename = "test.png"; 

    //image format 
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; 
    //pointer to the image, once loaded 
    FIBITMAP *dib(0); 
    //pointer to the image data 
    BYTE* bits(0); 
    //image width and height 
    unsigned int width(0), height(0); 
    //OpenGL's image ID to map to 
    GLuint gl_texID; 

    //check the file signature and deduce its format 
    fif = FreeImage_GetFileType(filename, 0); 
    //if still unknown, try to guess the file format from the file extension 
    if (fif == FIF_UNKNOWN) 
     fif = FreeImage_GetFIFFromFilename(filename); // >fif is assigned here correctly 
    //if still unkown, return failure 
    if (fif == FIF_UNKNOWN) 
     return false; 

    //check that the plugin has reading capabilities and load the file 
    if (FreeImage_FIFSupportsReading(fif)) 
     dib = FreeImage_Load(fif, filename); // >call retruns NULL every time 
    //if the image failed to load, return failure 
    if (!dib) 
     return false; // >Exits here due to failure 

    //retrieve the image data 
    bits = FreeImage_GetBits(dib); 
    //get the image width and height 
    width = FreeImage_GetWidth(dib); 
    height = FreeImage_GetHeight(dib); 
    //if this somehow one of these failed (they shouldn't), return failure 
    if ((bits == 0) || (width == 0) || (height == 0)) 
     return false; 

    // >Can't reach this from VS 
    std::cout << width << ", " << height << std::endl; 
    std::cin.get(); 

    return 0; 
} 

これは、発生します。 _NO_DEBUG_HEAPを1に設定してデバッグせずに試してみましたが、プログラムの動作に違いはありません。また、libを再コンパイルし、静的にも動的にもリンクしようとしましたが、違いはありません。

私の質問は次のとおりです。をデバッグするには何かできますか?に解決策がありますか?

+1

あなたのコードに基づいて、画像はアプリケーションの現在の作業ディレクトリにある必要があります。最初の作業ディレクトリは、アプリケーションの起動方法(デバッガやエクスプローラなど)によって異なる場合があります。確認して、それがすべて正しいことを確認します。 –

+0

@CaptainObvlious解決策を見つけて答えを投稿しました。ソース・ディレクションとビルド・ディレクションの両方にイメージがありましたが、ビジュアル・スタジオには問題がありました。 – ShadoWalkeR

答えて

0

解決策が見つかりました。問題は、デバッガを使用している間、Visual Studioはソースフォルダまたはビルドフォルダからファイルタイプを読み取ることができましたが、の両方ではなく、です。解決策は、ソースファイル(デバッガの場合)またはビルドディレクトリのいずれかにファイルを格納することでしたが、ではなく、です。

関連する問題