# \[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:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TAN](https://forums.unrealengine.com/u/TAN)\
**Post date:** [February 27, 2019, 11:21am UTC](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905/1 "2019-02-27T11:21:33Z")

</div>

Hello all. I am following this tutorial to make a n inventory. Pretty much followed closely (only difference is I am storing the inventory in a Game Instance rather than Character controller.)

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

I am getting a error and crush when I pick up an PickUpBase object. Report is here:

```auto

LoginId:483efdfe41b0c3bf539825b6b2adf55e
EpicAccountId:952fa0caa5f442c5a232d6b209904780

Access violation - code c0000005 (first/second chance not available)

UE4Editor_R7_4749!ASPR7GameState::GetItemDB() [e:\ue4\r7\source\r7\spr7gamestate.cpp:19]
UE4Editor_R7_4749!USPR7GameInstance::AddItemToInventoryByID() [e:\ue4\r7\source\r7\spr7gameinstance.cpp:24]
UE4Editor_R7_4749!APickUpBase::PickedUpByPlayer() [e:\ue4\r7\source\r7\pickupbase.cpp:31]
UE4Editor_R7_4749!AR7Character::PickupItem() [e:\ue4\r7\source\r7\r7character.cpp:247]
UE4Editor_Engine!FInputActionUnifiedDelegate::Execute() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\classes\components\inputcomponent.h:204]
UE4Editor_Engine!UPlayerInput::ProcessInputStack() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\userinterface\playerinput.cpp:1225]
UE4Editor_Engine!APlayerController::ProcessPlayerInput() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:2478]
UE4Editor_Engine!APlayerController::TickPlayerInput() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:4229]
UE4Editor_Engine!APlayerController::PlayerTick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:2142]
UE4Editor_Engine!APlayerController::TickActor() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:4323]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\actor.cpp:132]
UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:273]
UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\core\public\async	askgraphinterfaces.h:784]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:651]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:560]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:1330]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:542]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:1454]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:760]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1408]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1659]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:396]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3296]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

```

If I understand correctly the whole error and crash starts from GetItemDB() function in GameState which is just " return ItemDB; " basically returning the database. I checked some questions about “Access violation - code c0000005” and it seems people suggest checking pointers, however it seems to unrelated for this situation. ? I would really appreciate some help about understanding he crush report here. It has been 2-3 days and I am kinda stuck. Here are my code files if you wish to look at them.

https://www.dropbox.com/s/o2f0aa1tdb…yCode.rar?dl=0

I am using UE4 4.18.3 and VS 2017 with updates.

Thanks and respects.

---

<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.

---

<div class="post-metadata">

**Author:** ![NuLL3rr0r](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NuLL3rr0r](https://forums.unrealengine.com/u/NuLL3rr0r)\
**Post date:** [February 27, 2019, 9:33pm UTC](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905/3 "2019-02-27T21:33:35Z")

</div>

It gives you the exact function and line of code where the code crashes. Line 19 of e:\ue4\r7\source\r7\spr7gamestate.cpp isnide ASPR7GameState::GetItemDB() method. You can even check the value you are trying to access (probably null or even uninitialized) if you are using a debuger (running through e.g. Visual Studio, Qt Creator, …).

---

<div class="post-metadata">

**Author:** ![TAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TAN](https://forums.unrealengine.com/u/TAN)\
**Post date:** [February 28, 2019, 12:06pm UTC](https://forums.unrealengine.com/t/solved-access-violation-code-c0000005-first-second-chance-not-available/122905/4 "2019-02-28T12:06:24Z")

</div>

> [@ExtraLifeMatt](#):
>
> Likely whatever gamemode your level is using, isn’t the one you expect.

Welp, whopsie daisy. Thanks for that. This was the problem. Everything works well now.  
Thanks mate.

> [@NuLL3rr0r](#):
>
> It gives you the exact function and line of code where the code crashes. Line 19 of e:\ue4\r7\source\r7\spr7gamestate.cpp isnide ASPR7GameState::GetItemDB() method. You can even check the value you are trying to access (probably null or even uninitialized) if you are using a debuger (running through e.g. Visual Studio, Qt Creator, …).

Oh so it is really like that. Thanks mate.
