Thread: LoadFromFile() causes Windows 98 to freeze?

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    25

    LoadFromFile() causes Windows 98 to freeze?

    Okay I have narrowed down my problems. I know, I know, I am not the best coder. But here goes:

    To change pictures in my game, I am using LoadFromFile().

    ex:

    Code:
    Image1->Picture->LoadFromFile("ExampleFolder/ExamplePicture.bmp");
    As you much smarter than I people (meaning everyone) can tell, this loads the bitmap file "ExamplePicture.bmp" into TImage1.

    I have found that the reason my program freezes on Windows 98, is because of this way of loading bitmaps that I use.

    For example, if I use that line of code to show 20 or 30 different pictures, one after the other, a Windows 98 or Windows ME computer will freeze. This exact same program on a Windows 2000 or Windows XP computer wil run just fine.

    So:

    1. Is there any known conflict between Windows 98/ME and Windows 2000/XP that might be arising from the LoadFromFile function?

    2. If there is no "cure" for this, what different way of loading bitmaps could I use.

    Thank you all for any help!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I would say that you're not freeing some resource or other as you move from one picture to the next.

    If you load more pictures on 2K/XP, no doubt the same problem will appear.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318

    Wink

    Quote Originally Posted by Salem
    I would say that you're not freeing some resource or other as you move from one picture to the next.

    If you load more pictures on 2K/XP, no doubt the same problem will appear.
    I agree with that assessment.
    However, what is this "LoadFromFile" function? It does not seem to exist in MSDN?

    Can you observe the memory usage of your program as you load successive images and tell us if there is anything unexpected?

    Other than that, you can try:
    Code:
    m_hImage = LoadImage(GetModuleHandle(0), filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Thanks for the help guys.

    The "LoadFromFile" function is found in the Borland Library. Yes I know this is probably a horrible way of doing things.

    Thanks for the code iMalc. I will try that out to see if I can replace the old code and get it working on Windows 98.

    I would say that you're not freeing some resource or other as you move from one picture to the next.

    If you load more pictures on 2K/XP, no doubt the same problem will appear.
    It is possible that I am not freeing the resources properly, I will check on that. However, loading more pictures on 2K/XP does not cause the problem to appear. I'm guessing that this is due to 2K/XP handling resources MUCH better than 98/ME.

    I will be trying this advice today. I will leave an update later on.

    This is for my job hehe, so any additional help would be greatly appreciated. Thanks to all!

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    ugh working all day on this and no solution.

    What would be a good way to observe the memory usage as I load different files at a time?

    iMalc, I'm a little confused on how to use that line of code you supplied.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Stick with what you know - if you're using Borland's vcl 'TPicture'/'TImage' object(s) then look for some sort of 'Release' or 'free' method to free the resources associated with it (it might be 'delete', I'm not sure as I've not used Borland Builder in a long time - check the documentation). If it has no explicit method to do that then its destructor is probably responsible; you then need to look at the way you have written your code to ensure that one picture/image object is used for one image only or, if it's used mutliple times, that you free image resources between uses.

    If you're going to go down the winapi route then you're still going to have to use DeleteObject eventually on whatever gets returned from each LoadImage call.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Ken, thanks alot for your reply. I was thinking about this problem all day yesterday even though I was off of work, and you read my mind, only a little better.

    I did an experiment and created a program that simply loaded images into the image holder, and found that when they loaded VERY slowly one after the other, the entire system crashes in Windows 98 and Windows ME. (Testing the program and Windows 2000 and Windows XP).

    This has to be due to Windows 98/ME not handling resources correctly, which means that I have to make sure that the resources used for loading an image are freed after each load. Exactly what you said.

    Thanks for the input, I will be working on this during the day today, (I also have other things to work on before the projects first release, my boss is wanting it sooner and sooner each day lol.)

    I will keep updating my progress, even if it's only for my enjoyment hehe.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    http://www.delphifaq.com/faq/f100.shtml

    im getting closer! Even though that is delphi it still helped me get a little closer.

    Now I am about to test a version using a fix which I think might work, wish me luck! (Even though I doubt anyone is reading this now).
    Last edited by MidnightlyCoder; 03-17-2006 at 12:51 PM.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Nope, haven't fixed it yet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create DateTimePicker in Windows 98
    By cguest19 in forum Windows Programming
    Replies: 1
    Last Post: 02-13-2003, 10:24 AM
  2. Windows 98 api vs windows XP
    By Shadow12345 in forum Windows Programming
    Replies: 3
    Last Post: 10-01-2002, 05:58 AM
  3. Visual C++ / Windows 98
    By ... in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 11:01 AM
  4. Windows 98 Programming from the Ground Up
    By morbuz in forum Windows Programming
    Replies: 1
    Last Post: 09-09-2001, 03:27 PM