# \[SOLVED\] Access violation - code c0000005 (first/second chance not available)

**URL:** <https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 27, 2019, 11:21am UTC](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905 "2019-02-27T11:21:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ExtraLifeMatt](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/extralifematt/32/918695_2.png) [@ExtraLifeMatt](https://forums.unrealengine.com/u/ExtraLifeMatt)\
**Post date:** [February 27, 2019, 2:20pm UTC](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905/2 "2019-02-27T14:20:50Z")

</div>

That’s a null pointer crash. Likely your AddItemToInventoryByID is accessing a nullptr. If you’re using that code in the tutorial, I’d change it to this:

```auto

bool AInventoryController::AddItemToInventoryByID(FName ID)
{
**if (AInventoryGameState* GameState = Cast<AInventoryGameState>(GetWorld()->GetGameState()))**
    {
        UDataTable* ItemTable = GameState->GetItemDB();
        FInventoryItem* ItemToAdd = ItemTable->FindRow<FInventoryItem>(ID, "");

        if (ItemToAdd)
        {
            // If a Slot- or WeightLimit are not needed remove them in this line
            if (Inventory.Num() < InventorySlotLimit && GetInventoryWeight() + ItemToAdd->Weight <= InventoryWeightLimit)
            {
                Inventory.Add(*ItemToAdd);
                ReloadInventory();
                return true;
            }
        }
    }
    return false;
}

```

Likely whatever gamemode your level is using, isn’t the one you expect.

---

_[View the full topic](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905)._
