Page 1 of 1

CEGUI::String problem

Posted: Thu Aug 21, 2008 07:00
by celest_3rd
I have another problem :oops: :oops:

Code: Select all

class testitem : public CEGUI::Window
{
public:
   int i_no;
   CEGUI::String i_ID;
   CEGUI::String i_name;
   int i_quantity;
};


Code: Select all

void create(int pNo,CEGUI::String pID,CEGUI::String pName,CEGUI::String pDesc)
   {
      CEGUI::WindowManager &wm = CEGUI::WindowManager::getSingleton();
         // Item icon
         testitem *w1 = static_cast<testitem*>(wm.createWindow("TaharezLook/StaticImage","Item/Img:" + pID));
         w1->setArea(CEGUI::UDim(0,0),CEGUI::UDim(0,0),CEGUI::UDim(1,0),CEGUI::UDim(1,0));
         w1->setProperty("Image","set:MenuHotkey image:mmnF01Normal");
         w1->setProperty("MousePassThroughEnabled","true");
         w1->i_no = pNo;
         w1->i_ID = pID; // Program breaks here
         w1->i_name = pName;
         w1->i_quantity = 0;
....


Code: Select all

item items;
items.create(1,"0001","Potion 1","Potion for use");
items.create(2,"0002","Potion 2","Potion for use");


Program breaks down when it reaches to those line.

How can I fix them ?
Thanks in advanced.

Posted: Thu Aug 21, 2008 07:44
by scriptkid
Hi,

i think that you have some invalid code. You cast the Window to your 'testitem' class, which is larger. So you start writing out of the memory boundaries for that class. Even if this would work (maybe in Debug mode), the members (the "i_xxx's") have not been created at all(!)

In order to derive a class from Window and do what you are doing, you need to modify the Cegui sources and add a Factory.

It might be easier to change your design, so that the created window become a member. Is that possible? For example:

Code: Select all

class testitem
{
public:
  testitem(CEGUI::Window wrapped) {
    m_wrapped = wrapped;
  }
  // other code + members
}


Then in the window creation method:

Code: Select all

// Item icon
testitem *w1 = new testitem(wm.createWindow("TaharezLook/StaticImage","Item/Img:" + pID));
w1->i_no = pNo;


HTH.

Posted: Thu Aug 21, 2008 12:35
by celest_3rd
Thanks scriptkid for acknowledges :)

I can't resolve problem about Item recognize when user drags Icon into slot (#3506)

I think 2 ways now!

1. use associative array
- user drags icon into slot (in example: result is "Item/Drag:Item0001" (DragContainer) at "EquipContain/Head")
- substring "Item/Drag:Item0001" with first-find-of ":" to end (result would be "Item0001"
- compare with hash array Items but result is blank

2. inheriete CEGUI::Window class
- I tested this code

Code: Select all

class testitem : public CEGUI::Window
{
int i_name;
int i_no;
}

// --- somewhere of code ----
testitem* test1 = static_cast<testitem*>(wmgr.getWindow("Test1"));
test1->i_name = 22222;
test1->i_no = 50;


It works! and I can use class attributes (i_name and i_no) anywhere if I call getWindow("Test1") both set/get.

But CEGUI::String attribute give me program breaks because it can't assign value with operation =