Crash adding items to Listbox

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

quasius
Just popping in
Just popping in
Posts: 14
Joined: Tue Mar 25, 2008 15:56

Crash adding items to Listbox

Postby quasius » Fri Apr 04, 2008 19:33

Here is the code I'm trying to use:

Code: Select all

void GUIManager_Editor::PopulateListBox(string sListboxName, vector<string> vOptions)
{
   CEGUI::WindowManager& windowManager = CEGUI::WindowManager::getSingleton();
   CEGUI::Listbox* pListbox = (CEGUI::Listbox*)(windowManager.getWindow(sListboxName.c_str()));

   for (unsigned int i = 0; i < vOptions.size(); ++i)
   {
      pListbox->addItem(new CEGUI::ListboxTextItem(vOptions[i].c_str()));
   }
}


This is causing a crash when the text item is added. Specifically, it's crashing a crash on line 302 of ceguilistbox.cpp in Listbox::addItem.
It says Debug assertion failed: invalid Null pointer. The passed ListboxItem* is not Null.
The listbox works fine if I populate it from a layout file, but I need to be able to add to it at runtime. Any ideas?

Edit: Not sure if it's relevant, but the window is being created with the following xml:

Code: Select all

<Window Type="WindowsLook/ItemListbox" Name="TileDirSelectListBox" >
            <Property Name="UnifiedPosition" Value="{{0.155,0},{0.206,0}}" />
            <Property Name="UnifiedSize" Value="{{0.14,0},{0.755,0}}" />
</Window>

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

Postby CrazyEddie » Sat Apr 05, 2008 08:56

Hi, and welcome :)

The issue is that you have created a new model ItemListbox, but then cast and use it as an old model Listbox.

The easiest change is to modify the layout to use "WindowsLook/Listbox" instead.

If you want to use the new model ItemListbox, then your code should look something like this:

Code: Select all

void GUIManager_Editor::PopulateListBox(string sListboxName, vector<string> vOptions)
{
   CEGUI::WindowManager& windowManager = CEGUI::WindowManager::getSingleton();
   CEGUI::ItemListbox* pListbox = (CEGUI::ItemListbox*)(windowManager.getWindow(sListboxName.c_str()));

   for (unsigned int i = 0; i < vOptions.size(); ++i)
   {
      CEGUI::ItemEntry* item =
        (CEGUI::ItemEntry*)windowManager.createWindow("WindowsLook/ListboxItem");

      item->setText(vOptions[i].c_str());

      pListbox->addItem(item);
   }
}


CE.

quasius
Just popping in
Just popping in
Posts: 14
Joined: Tue Mar 25, 2008 15:56

Postby quasius » Sat Apr 05, 2008 14:40

Thank you very much. It works fine now. Great library!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 16 guests