Page 6 of 6

Re: Inventory/Container GUI

Posted: 18 May 2012, 20:34
by scrawl
Stumbled upon a bug in ContainerStore. I'm adding bought items to a separate ContainerStore (in order to make them not stack with already owned items) Now I want to check if any items were bought with this code:

Code: Select all

        if (playerBought.begin() == playerBought.end())
This doesn't work when I buy an item and then sell it to the vendor again (which sets the count of the item in the containerstore to 0). In that case the comparison returns false, even though it should be true because there are no items with count != 0 in the container.

Edit: Nevermind, I think the problem is somewhere else...

Re: Inventory/Container GUI

Posted: 18 May 2012, 21:03
by scrawl
I did more testing and it seems indeed like a ContainerStore bug. After adding one item to the container store and removing it again, the following code

Code: Select all

        for (MWWorld::ContainerStoreIterator it = playerBought.begin();
                it != playerBought.end(); ++it)
        {
            std::cout << "item in playerbought with count " << it->getRefData().getCount() << std::endl;
        }
yields the output "item in playerbought with count 0" - yet, the ContainerStoreIterator is supposed to skip over items with count 0 automatically.

Not a big problem, because I can just check for the count, but I thought I'd let you know. I use this now and it works:

Code: Select all

        bool traded=false;
        for (MWWorld::ContainerStoreIterator it = playerBought.begin();
                it != playerBought.end(); ++it)
        {
            if (it->getRefData().getCount() > 0)
                traded = true;
        }

Re: Inventory/Container GUI

Posted: 18 May 2012, 21:24
by Zini
Does the fix in my iterator branch help?

Re: Inventory/Container GUI

Posted: 18 May 2012, 21:30
by scrawl
Nice, fixed!

Re: Inventory/Container GUI

Posted: 19 May 2012, 14:52
by Zini
Problem. A big one. Unfortunately. Weight calculations don't work and it looks like some data structures are completely messed up.

I found casts to InventoryStore references in the GUI code and I suspect these are the source of the problem. Please remove them all. There is an getInventoryStore function in MWWorld::Class, that you can use instead for NPCs. Creatures and containers on the other hand don't have an InventoryStore at all.

Re: Inventory/Container GUI

Posted: 19 May 2012, 15:05
by scrawl
Done.
Creatures and containers on the other hand don't have an InventoryStore at all.
That is handled.

Re: Inventory/Container GUI

Posted: 19 May 2012, 15:32
by Zini
Hm ... That does not fix anything. Seems my guess was wrong. Anyway, its good that we got rid of these casts.

Re: Inventory/Container GUI

Posted: 19 May 2012, 16:37
by Zini
Found the problem. Some of my recent changes regarding magic effects broke the inventory store.