Please help me with SDL_image

This is a discussion on Please help me with SDL_image within the C++ Programming forums, part of the General Programming Boards category; I am follwing Lazy foo's tutorials, but have run into a problem with SDL_image, the program I have copied from ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    10

    Please help me with SDL_image

    I am follwing Lazy foo's tutorials, but have run into a problem with SDL_image, the program I have copied from the tutorial (that countless others must have used) compiles with no errors or warnings. I have checked that all the .lib and .dll files are where they are supposed to be, have added SDL_image.lib, SDL.lib and SDLmain.lib to the additional dependencies etc. etc.

    Yet when I run the program all it does is flash up with the command screen for the smallest amount of time, which then disappears so fast you can hardly see it...why would this happen?

    I am using Visual c++ 2008 Express on Windows XP if that helps.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Does your application actually contain anything that makes it "stay"? E.g. an infinite loop, waiting for the keyboard, or some such?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    46
    matsp, assuming he uses the default code provided on lazyfoo's page, there is a delay of around 2 seconds before the app closes.

    Assuming it just quits without any message, compile a debug version, then run it through Debug -> Start Debugging. Then see what exit code your program returns, and where it exits. Chances are that you have miss placed the image you're trying to load. But until you share a bit more info, there's no way of knowing.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    10
    I think I am doing the tutorial after the one you are thinking of, not the one with the 2 second pause, but the one where it is supposed to wait for the user to click the 'x' to close the window...

    When debugging it says that the program returns 1, and it seems to be because IMG_load() isn't getting an image...but there is no reason why it shouldn't...the .png file is in the project folder etc. ...

    EDIT: This is what it says after the debug:
    The thread 'Win32 Thread' (0x264) has exited with code 1 (0x1).
    The thread 'Win32 Thread' (0x948) has exited with code 1 (0x1).
    The program '[3004] Event driven prog.exe: Native' has exited with code 1 (0x1).
    Last edited by KnightAdz; 11-26-2008 at 04:06 PM.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    46
    I believe that when you're running the program you've written from within visual studio, you have to place the image file in the same folder as your .cpp and .h files. That is Projects/(Project Name)/(Project Name), and when running the .exe from explorer or the command line you have to place it in (depending on whether you run debug or release config) Projects/(Project Name)/Debug or Projects/(Project Name)/Release.

    But could be that other people had more useful input?

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    10
    Yea, that is where the file is, but as near as I can tell, for some reason IMG_Load() will not load it and so the program doesn't run properly. It can't be a problem with the code because I have copied and pasted Lazy foo's code....so it must be some sort of problem with SDL_image...i think...

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by KnightAdz View Post
    so it must be some sort of problem with SDL_image...i think...
    I don't think so. It is extremely rare that it is the code you are calling, in a much used library, that is the cause of problems when things go wrong. If SDL_image is broken in a trivial use-case, then it would have been discovered by now.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    10
    Yes I agree, what I meant (although it didn't come out well) was that I think I haven't set-up SDL_image correctly, however I have followed the tutorials on how to exactly, and there have been no errors, yet IMG_Load will not load the .png file...

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, perhaps you should post the code?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    10
    The source code I'm using is here:

    http://lazyfoo.net/SDL_tutorials/lesson04/index.php

    I downloaded it and the source files so that I was using the same as what everybody else must have, it compiles fine, but when I run it nothing happens...

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21