mfc LoadBitmap hangs my application...
-
VS2008, Windows Embedded Compact 7, mfc dialog application that is 4 years old. It's been working fine. Today I've been making improvements, tracking down some long standing issues. Up until this afternoon, I could pretty much debug where I wanted but then suddenly my UI loop stalled in the OnInitDialog. Stepping through, I came to a couple of LoadBitmap calls that I use to load images from the embedded resources. The first call does not error out, it just never comes back from the LoadBitmap call. This smells like some weird elephanting debris from VS2008. Some references suggest memory issues on the target device, etc, but it's been rebooted, this is a lightweight app... and doesn't use much memory. Anyone seen LoadBitmap stall like this?
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
VS2008, Windows Embedded Compact 7, mfc dialog application that is 4 years old. It's been working fine. Today I've been making improvements, tracking down some long standing issues. Up until this afternoon, I could pretty much debug where I wanted but then suddenly my UI loop stalled in the OnInitDialog. Stepping through, I came to a couple of LoadBitmap calls that I use to load images from the embedded resources. The first call does not error out, it just never comes back from the LoadBitmap call. This smells like some weird elephanting debris from VS2008. Some references suggest memory issues on the target device, etc, but it's been rebooted, this is a lightweight app... and doesn't use much memory. Anyone seen LoadBitmap stall like this?
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
Did you tried to load another bitmap, something small in order to find out where is the problem ?
I actually did... there are only three bitmaps in the project. I added some code:
CBitmap myBitmap;
myBitmap.LoadBitmap(IDB_STOP);it never returns from the LoadBitmap... very odd. The bitmaps are not large (200x200?), and the really weird part, again, is that this code has been working for many years.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
I actually did... there are only three bitmaps in the project. I added some code:
CBitmap myBitmap;
myBitmap.LoadBitmap(IDB_STOP);it never returns from the LoadBitmap... very odd. The bitmaps are not large (200x200?), and the really weird part, again, is that this code has been working for many years.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
I would try a little workaround: use CImage instead of CBitmap ... at least you will know where is the problem, or, you will solve the issue .... However, CBitmap is reliable ... I don't think that code from above is causing the problem ... the cause must be in else where.
-
I actually did... there are only three bitmaps in the project. I added some code:
CBitmap myBitmap;
myBitmap.LoadBitmap(IDB_STOP);it never returns from the LoadBitmap... very odd. The bitmaps are not large (200x200?), and the really weird part, again, is that this code has been working for many years.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Check you have not got a clash on IDB_STOP and you actually have the resource of that ID in the project. All you need is a corrupt resource file and it can't connect the dots.
In vino veritas
-
Check you have not got a clash on IDB_STOP and you actually have the resource of that ID in the project. All you need is a corrupt resource file and it can't connect the dots.
In vino veritas
-
Check you have not got a clash on IDB_STOP and you actually have the resource of that ID in the project. All you need is a corrupt resource file and it can't connect the dots.
In vino veritas
good idea, "use the source luke"... looking now - yeah, this looks good. I would expect the loadbitmap operation would just fail and not hang. The resource is built into the exe. Trying the load image... I love you Microsoft.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
good idea, "use the source luke"... looking now - yeah, this looks good. I would expect the loadbitmap operation would just fail and not hang. The resource is built into the exe. Trying the load image... I love you Microsoft.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
So, tried the CImage -> LoadImage approach - no go. Hangs in that call as well. I'm going to sell my house and buy a sailboat.... elephanting code - okay, I figured out why the call hangs. This application is my application loader code in an embedded target. We have two types of upgrades - one with and one without an operating system. So, one thing I need to do is dismount and remount the device partitions (this is Windows Embedded Compact 7), so I can modify OS files. This typically is not a concern, since by the time we're running, everything is running out of ram. Once complete, the device reboots. No harm. Now I don't know how LoadBitmap is implemented, but it appears that it reads the resource information from the exe file and not what is in RAM. Egg on my face since I missed the #define change. I still argue that LoadBitmap should return gracefully with an error code. Heh it's mfc, filed under "don't do that." Appreciate all the suggestions.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
-
So, tried the CImage -> LoadImage approach - no go. Hangs in that call as well. I'm going to sell my house and buy a sailboat.... elephanting code - okay, I figured out why the call hangs. This application is my application loader code in an embedded target. We have two types of upgrades - one with and one without an operating system. So, one thing I need to do is dismount and remount the device partitions (this is Windows Embedded Compact 7), so I can modify OS files. This typically is not a concern, since by the time we're running, everything is running out of ram. Once complete, the device reboots. No harm. Now I don't know how LoadBitmap is implemented, but it appears that it reads the resource information from the exe file and not what is in RAM. Egg on my face since I missed the #define change. I still argue that LoadBitmap should return gracefully with an error code. Heh it's mfc, filed under "don't do that." Appreciate all the suggestions.
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
I agree LoadBitmap should not fail like that but it is specified the resources are never lifted into RAM. They are tagged in special sections in the file and are excluded from the normal executable load to avoid using memory when not required. Remember a file may contain many resources for different resolutions, languages and the like and much would then be redundant duplicates hogging memory.
In vino veritas
-
I agree LoadBitmap should not fail like that but it is specified the resources are never lifted into RAM. They are tagged in special sections in the file and are excluded from the normal executable load to avoid using memory when not required. Remember a file may contain many resources for different resolutions, languages and the like and much would then be redundant duplicates hogging memory.
In vino veritas
:thumbsup:
Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759