Inventory/Container GUI

Everything about development and the OpenMW source code.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Inventory/Container GUI

Post 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...
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Inventory/Container GUI

Post 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;
        }
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory/Container GUI

Post by Zini »

Does the fix in my iterator branch help?
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Inventory/Container GUI

Post by scrawl »

Nice, fixed!
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory/Container GUI

Post 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.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Inventory/Container GUI

Post by scrawl »

Done.
Creatures and containers on the other hand don't have an InventoryStore at all.
That is handled.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory/Container GUI

Post by Zini »

Hm ... That does not fix anything. Seems my guess was wrong. Anyway, its good that we got rid of these casts.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Inventory/Container GUI

Post by Zini »

Found the problem. Some of my recent changes regarding magic effects broke the inventory store.
Post Reply