A doubt abou popmenu

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

User avatar
thejinchao
Just popping in
Just popping in
Posts: 11
Joined: Tue Aug 23, 2005 08:00
Location: Beijing. China
Contact:

A doubt abou popmenu

Postby thejinchao » Mon Sep 05, 2005 03:39

My application always crash when i click any menuitem in a popmenu. The key code is below:

Code: Select all

void MenuItem::closeAllMenuItemPopups()
{
   // are we attached to a PopupMenu?
   PopupMenu* pop = (PopupMenu*)getParent();
   if (getParent()->testClassName("PopupMenu") && pop->isItemInList(this))
   {
      // is this parent popup attached to a menu item?
      MenuItem* item = (MenuItem*)pop->getParent();
      if (item!=NULL && item->testClassName("MenuItem"))
      {
         // close popup
         item->closePopupMenu();
         // recurse
         item->closeAllMenuItemPopups();
      }
      // otherwise we just hide ourselves
      else
      {
         //----------------------------------
         //ATTENTION HERE!!!!
         //If "item" is NOT a MenuItem class, this line will crash the application
         //----------------------------------
         item->closePopupMenu();
      }
   }
}

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: A doubt abou popmenu

Postby CrazyEddie » Mon Sep 05, 2005 08:23

I'm sure you'll appreciate that with the amount of code there is in the library, combined with the large probability that the issue is in the client code, saying "it crashes" is of little use to us when trying to help you ;)

You need to debug this and at least post the exception that you're getting and a debug stack trace of some description.

Thanks.

User avatar
Blakharaz
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Wed Jan 12, 2005 12:06
Location: Potsdam, Germany
Contact:

Re: A doubt abou popmenu

Postby Blakharaz » Mon Sep 05, 2005 08:50

You are using this C cast

Code: Select all

MenuItem* item = (MenuItem*)pop->getParent();

So every parent of pop is cast to a MenuItem pointer. You can't call a method on this pointer if it is NULL (I bet this is the case, since the else branch includes the case of item being NULL) or not a MenuItem.
The cast always works, since this is a C cast (use dynamic_cast when CEGUI is compiled with RTTI to be sure, or at least static_cast, these are easier to locate in the code), but you must be sure to have a pointer of the right type, or else your next method call will fail.
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)

User avatar
thejinchao
Just popping in
Just popping in
Posts: 11
Joined: Tue Aug 23, 2005 08:00
Location: Beijing. China
Contact:

Re: A doubt abou popmenu

Postby thejinchao » Tue Sep 06, 2005 01:37

Sorry for my halfhearted :oops:
I found the actual reason is my wrong method of create.
I wrote menuitem in layout file as "sub window"

Code: Select all

<Window Type="MyLook/PopupMenu" Name="ContexMenu_OtherPlayer">
   ...
   <Window Type="MyLook/MenuItem" Name="OtherPlayer_Observe">
      <Property Name="Text" Value="{ID=OBSERVE}" />
      ...
   </Window>
   ...
</Window>


I found menuitem can't be added as a "subitem" in popupmenu.
The function MenuItem::setPopupMenu wasn't be executed at all. So, the exception will appear when i clicked a menuitem.
So..., I am little confused about it. Is there a method to create a whole menu(include menuitem) in a layout file?
Sorry for my poor english :oops:

User avatar
Blakharaz
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Wed Jan 12, 2005 12:06
Location: Potsdam, Germany
Contact:

Re: A doubt abou popmenu

Postby Blakharaz » Tue Sep 06, 2005 12:29

Just use PopupMenuItem instead of just MenuItem, that should do.

To provide a complete menu bar in a XML file use something like

Code: Select all

<Window Type="Look/Menubar" Name="MainMenu">
       <Window Type="Look/MenubarItem" Name="MainMenu/Item1">
              <Property Name="Text" Value="Item1"/>

              <Window Type="Look/PopupMenu" Name="MainMenu/Item1/Menu">
                    <Window Type="RastullahLook/PopupMenuItem" Name="MainMenu/Item1/Item1">
                          <Property Name="Text" Value="Item1"/>
                    </Window>

                    <Window Type="Look/PopupMenuItem" Name="MainMenu/Item1/Item2">
                          <Property Name="Text" Value="Item2"/>
                    </Window>
              </Window>
        </Window>
    </Window>
</GUILayout>
Coder in the Pantheon Team - creators of "Rastullahs Lockenpracht" (http://www.rastullahs-lockenpracht.de/)

User avatar
thejinchao
Just popping in
Just popping in
Posts: 11
Joined: Tue Aug 23, 2005 08:00
Location: Beijing. China
Contact:

Re: A doubt abou popmenu

Postby thejinchao » Tue Sep 06, 2005 13:35

Thank you,I see it :)
Sorry for my poor english :oops:


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests