Inventory

Everything about development and the OpenMW source code.
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Inventory

Post by lgromanowski »

Code: Select all

int oldcount=(mItems.find(_sender) != mItems.end())
  ?  &*mItems.find(_sender))->second.getRefData().getCount()
  : 800; //not helps (oldcount != 800)
You search for _sender twice, why? Why not just simple:

Code: Select all

typedef .... ItemsContainer;

int oldcount = 800;
ItemsContainer::iterator it = mItems.find(_sender);
if (it != mItems.end())
{
  oldcount = it->second.getRefData().getCount();
}
?
akebono
Posts: 9
Joined: 13 Aug 2011, 10:13

Re: Inventory

Post by akebono »

indeed. thank you) but main point persist\. std::map<MyGUI::WidgetPtr, MWWorld::Ptr> mItems. In mItems.find() second element seemls like totally inexistant, (exist only in function with mItems.insert(std::make_pair(...widget,..ptr)), here it works fine. Here comes the crash upon calling methods of the second element of map: https://github.com/akebono/openmw/commi ... 56f54eecbf
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Inventory

Post by lgromanowski »

akebono wrote:indeed. thank you) but main point persist\. std::map<MyGUI::WidgetPtr, MWWorld::Ptr> mItems. In mItems.find() second element seemls like totally inexistant, (exist only in function with mItems.insert(std::make_pair(...widget,..ptr)), here it works fine. Here comes the crash upon calling methods of the second element of map: https://github.com/akebono/openmw/commi ... 56f54eecbf
To avoid crash change itemList parameter in drawItemWidget() method to reference.

// EDIT: "All" button is to tight and localized strings don't fit there (in Polish language there should be "Ca?o??" but only "Ca?o?" is visible).
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Inventory

Post by sirherrbatka »

// EDIT: "All" button is to tight and localized strings don't fit there (in Polish language there should be "Ca?o??" but only "Ca?o?" is visible).
We can creat custom polish string "Ca?us" that will fit the place :D
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Inventory

Post by lgromanowski »

sir_herrbatka wrote:
// EDIT: "All" button is to tight and localized strings don't fit there (in Polish language there should be "Ca?o??" but only "Ca?o?" is visible).
We can creat custom polish string "Ca?us" that will fit the place :D
Rotfl :D
akebono
Posts: 9
Joined: 13 Aug 2011, 10:13

Re: Inventory

Post by akebono »

something happening wrong while i map::insert:

in header i have

Code: Select all

std::map<MyGUI::StaticImagePtr, MWWorld::Ptr*> mItems;
(which i typedef std::map<MyGUI::StaticImagePtr, MWWorld::Ptr*> mapItems;)
In

Code: Select all

template<class T> 
drawItemWidget(std::list<ESMS::LiveCellRef<T, MWWorld::RefData> > itemlist){
i do

Code: Select all

 
for(typename std::list<ESMS::LiveCellRef<T, MWWorld::RefData> >::iterator it = itemlist.begin(); it != itemlist.end(); it++){
MWWorld::Ptr *ptr=new Ptr(&*it,0);
...creating of widget..., than

Code: Select all

mItems.insert(std::make_pair(widget,ptr);
and
in the end of function after loop i just look at elements in map :

Code: Select all

for(mapItems::iterator it=mItems.begin();it!=mItems.end();it++){
        printf("z1 %s:%i\n",MWWorld::Class::get (*(&*it)->second).getInventoryIcon (*(&*it)->second).c_str(), (&*it)->second->getRefData().getCount());
}
which crushes on second iteration if i picked up more than 1 item:\

mItems.size() rise properly, mItems[someproperwidget] works too, but the second element seems like hell's mess
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory

Post by Zini »

lgro already explained to you what was wrong (the missing reference).

Also, could you please lose all that ptr newing? You already have produced a memory leak with it.
akebono
Posts: 9
Joined: 13 Aug 2011, 10:13

Re: Inventory

Post by akebono »

ok Lukasz, fixed the thing. but now guys there is exception in approximately same place upon ".get(ptr)" which throw thing about non-existant key ( "ERROR: unknown class key:" and no key name, but key.c_str() yields the stuff)
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory

Post by Zini »

You are trying to get a class instance for the MWWorld::Ptr equivalent of a 0-pointer.
akebono
Posts: 9
Joined: 13 Aug 2011, 10:13

Re: Inventory

Post by akebono »

oh yeah), it works) ty, dumb me\
Post Reply