0

単純なコードのイメージ ポインターはなぜ NULL ですか?:

    // defined in the header files 
    SDL_Surface* m_imageIcon;
    SDL_Surface* m_CharMainTile;


    bool SDLmanager::loadFiles()
    {

        m_imageIcon = loadImage("D:\\java\\workspace\\SDL_test1\\Debug\\robot1.bmp",type_bmp);
/*
mem print as you see empty 
Name : m_imageIcon
    Details:0x0
    Default:0x0
    Decimal:0
    Hex:0x0
    Binary:0
    Octal:0




*/
        m_CharMainTile = loadImage("D:\\java\\workspace\\SDL_test1\\Debug\\vx_chara09_d.png",type_png);
        bool b = false;

        if(m_imageIcon == NULL) // this is null 
            b = true;
        if(m_CharMainTile == NULL) // this is null 
            b = true;

        if(!b)
            return false;
        return true;


    }

これは、すべて有効で、指定されたパスにファイルを設定する場所です

   SDL_Surface *SDLmanager::loadImage( string filename , imgType t)
    {
        //Temporary storage for the image that's loaded
        SDL_Surface* loadedImage = NULL;

        //The optimized image that will be used
        SDL_Surface* optimizedImage = NULL;

        //Load the image
        if(t== type_bmp)
        {
            loadedImage = SDL_LoadBMP( filename.c_str() );
        }
        else
        {
            loadedImage = IMG_Load( filename.c_str() );
        }

        //If nothing went wrong in loading the image
        if( loadedImage != NULL )
        {
            //Create an optimized image
            optimizedImage = SDL_DisplayFormat( loadedImage );

            //Free the old image
            SDL_FreeSurface( loadedImage );
        }

        //Return the optimized image
        return optimizedImage;
    }

optimizedImage には有効なアドレスと値があります

Name : optimizedImage
    Details:0x4d6ea8
    Default:0x4d6ea8
    Decimal:5074600
    Hex:0x4d6ea8
    Binary:10011010110111010101000
    Octal:023267250

コンパイルは問題なくきれいです:

make all 
Building file: ../Main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"Main.d" -MT"Main.d" -o "Main.o" "../Main.cpp"
Finished building: ../Main.cpp

Building file: ../SDLmanager.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"SDLmanager.d" -MT"SDLmanager.d" -o "SDLmanager.o" "../SDLmanager.cpp"
Finished building: ../SDLmanager.cpp

Building target: SDL_test1.exe
Invoking: MinGW C++ Linker
g++  -o "SDL_test1.exe"  ./Main.o ./SDLmanager.o   -lmingw32 -lSDL_image -lSDLmain -lSDL
Finished building target: SDL_test1.ex
4

0 に答える 0