Hardeep Singh
April 29th, 1999, 06:17 AM
I'm having quite a lot of trouble with a program, which uses arrays of popup menus.
It creates global arrays of menus, and later when it needs them, it calls CreatePopupMenu() for as many CMenus as needed, in a loop. Here, It gives a Debug Assertion failure, since there's no check for the validity of the CMenu object. This problem is solved only when I test if the m_hMenu member is not NULL (I've tried IsMenu() and GetSafeHmenu()... both use this fundamental check as one of the conditions, and this one alone works well here).
But when I do this, I later get another Assertion Failure when I try to call AppendMenu with the same menu object. On debugging, I find that the particular object has m_hMenu equal to NULL.
Now what do I do? While creating, I have problems because the menu handle IS NOT NULL, and (if I check that) while appending, I have problems if it IS NULL. Is there a better, more reliable way of creating and filling up arrays of CMenus without these problems? This problem does not happen with the simple menu objects, only with the arrays.
Needless to say, when I build the app in Release mode, it runs, but crashes often. I can't give up arrays altogether, since I don't have time to rewrite the whole program, and I'm actually working on a prewritten program, just trying to fix it.
I mentioned that only as many menus are created as required, so the arrays may not be full, but this is not a simple problem of crossing the bounds or accessing some array element outside of the initialized range... I've checked that. the array indices are well within range and the loops begin and end properly.
Whatever the case, this is urgent and I'll really really be grateful if anyone can help me out.
Thanks,
-Hardeep.
It creates global arrays of menus, and later when it needs them, it calls CreatePopupMenu() for as many CMenus as needed, in a loop. Here, It gives a Debug Assertion failure, since there's no check for the validity of the CMenu object. This problem is solved only when I test if the m_hMenu member is not NULL (I've tried IsMenu() and GetSafeHmenu()... both use this fundamental check as one of the conditions, and this one alone works well here).
But when I do this, I later get another Assertion Failure when I try to call AppendMenu with the same menu object. On debugging, I find that the particular object has m_hMenu equal to NULL.
Now what do I do? While creating, I have problems because the menu handle IS NOT NULL, and (if I check that) while appending, I have problems if it IS NULL. Is there a better, more reliable way of creating and filling up arrays of CMenus without these problems? This problem does not happen with the simple menu objects, only with the arrays.
Needless to say, when I build the app in Release mode, it runs, but crashes often. I can't give up arrays altogether, since I don't have time to rewrite the whole program, and I'm actually working on a prewritten program, just trying to fix it.
I mentioned that only as many menus are created as required, so the arrays may not be full, but this is not a simple problem of crossing the bounds or accessing some array element outside of the initialized range... I've checked that. the array indices are well within range and the loops begin and end properly.
Whatever the case, this is urgent and I'll really really be grateful if anyone can help me out.
Thanks,
-Hardeep.