This object is in archive! 
IMyInventory.GetAcceptedItems() throws a NullReferenceException for unconstrained inventories
Solved
If an inventory doesn't have a constraint set (i.e. accepts any items, like cargo container), then using GetAcceptedItems() on this inventory will throw a NullReferenceException.
Example Code:
public void Main(string argument, UpdateType updateSource) { IMyTerminalBlock g = GridTerminalSystem.GetBlockWithName("Small Cargo Container"); if (g == null) { Echo("No such block"); return; } Echo(g.CustomName); List<MyItemType> items = new List<MyItemType>(); for (int i = 0; i < g.InventoryCount; i++) { IMyInventory inv = g.GetInventory(i); Echo(inv.ToString()); items.Clear(); inv.GetAcceptedItems(items); //BOOM! Echo($"Inventory accepts {items.Count} types"); } }
Hello, Engineer!
Thank you for your feedback! Your topic has been added between considered issues.
Please keep voting for the issue as it will help us to identify the most serious bugs.
We really appreciate your patience.
Kind Regards
Keen Software House: QA Department
Hello, Engineer!
Thank you for your feedback! Your topic has been added between considered issues.
Please keep voting for the issue as it will help us to identify the most serious bugs.
We really appreciate your patience.
Kind Regards
Keen Software House: QA Department
And for whoever fixes this, please take a look at what GetAcceptedItems() iterates:
I've tested that exact code with a mod and it only gives weapons, therefore even if this NRE is fixed the method is still useless.
And for whoever fixes this, please take a look at what GetAcceptedItems() iterates:
I've tested that exact code with a mod and it only gives weapons, therefore even if this NRE is fixed the method is still useless.
Fixed in hotfix 191.106. Release: 01.07.2019
Fixed in hotfix 191.106. Release: 01.07.2019
Replies have been locked on this page!