SEModCommunity / SE-Community-Mod-API

Space Engineers Community Modding API
GNU Lesser General Public License v3.0
60 stars 47 forks source link

BUG: Setting/changing multiple InventoryEntityItem.Amount values on the same InventoryEntity #128

Closed Tyrsis closed 10 years ago

Tyrsis commented 10 years ago

Here's the main reason:

In SEModAPIInternal.API.Entity.inventoryEntity:

To update an item you do: Inventory.UpdateItemAmount();

Which calls: SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);

Which then triggers a call to: InternalUpdateItemAmount()

Then inside that, you either invoke a call to remove inventory items, or add some. The problem is this process isn't synchronous, and you're using globals in InternalUpdateItemAmount. So this means that if you do multiple UpdateItemAmount() calls on the same Inventory, the globals get overwritten each time before InternalUpdateItemAmount gets called, so only one item will ever get updated (depending on what m_itemToUpdate refers to at the time).

I was trying to update multiple item counts in a cargo container, and only one is ever getting updated, and was completely stumped for awhile.

I made a work around for this by just tossing it into a locked queue. The work around works as expected, and can probably be rolled into the main API. Or you can update with a fix as you see fit.

Code used for fix: http://pastebin.com/vKERp2hq

Obviously since these are part of the Entity class itself, you won't need the inventoryentity when updating the API.

chessmaster42 commented 10 years ago

This should be fixed in the latest dev build. Please update and re-test and let us know if this is still an issue.

Tyrsis commented 10 years ago

Yup, this works now, thanks. (Can remove the hackiness I was doing :)