@@ -529,10 +529,10 @@ void DrawInventoryTab() {
529529 " Restrict to valid items" , &restrictToValid,
530530 checkboxOptionsBase.Tooltip (" Restricts items and ammo to only what is possible to legally acquire in-game" ));
531531
532- for (int32_t y = 0 ; y < 4 ; y++) {
533- for (int32_t x = 0 ; x < 6 ; x++) {
534- int32_t index = x + y * 6 ;
535- static int32_t selectedIndex = - 1 ;
532+ for (uint32_t y = 0 ; y < 4 ; y++) {
533+ for (uint32_t x = 0 ; x < 6 ; x++) {
534+ uint32_t index = x + y * 6 ;
535+ static uint32_t selectedIndex = UINT32_MAX ;
536536 static const char * itemPopupPicker = " itemPopupPicker" ;
537537
538538 ImGui::PushID (index);
@@ -541,7 +541,8 @@ void DrawInventoryTab() {
541541 ImGui::SameLine ();
542542 }
543543
544- uint8_t item = gSaveContext .inventory .items [index];
544+ static_assert (sizeof (gSaveContext .inventory .items ) / sizeof (gSaveContext .inventory .items [0 ] == 24 ));
545+ ItemID item = index < 24 ? (ItemID)gSaveContext .inventory .items [index] : ITEM_NONE ;
545546 PushStyleButton (Colors::DarkGray);
546547 if (item == ITEM_ROCS_FEATHER ) {
547548 auto ret = ImGui::ImageButton (
@@ -553,8 +554,8 @@ void DrawInventoryTab() {
553554 selectedIndex = index;
554555 ImGui::OpenPopup (itemPopupPicker);
555556 }
556- } else if (item != ITEM_NONE ) {
557- const ItemMapEntry& slotEntry = itemMapping. find (item) ->second ;
557+ } else if (auto mappedItem = itemMapping. find ( item); item != ITEM_NONE && mappedItem != itemMapping. end () ) {
558+ const ItemMapEntry& slotEntry = mappedItem ->second ;
558559 auto ret = ImGui::ImageButton (
559560 slotEntry.name .c_str (),
560561 std::dynamic_pointer_cast<Fast::Fast3dGui>(Ship::Context::GetRawInstance ()->GetWindow ()->GetGui ())
0 commit comments