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

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

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


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.

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:



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.

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, …).

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

Oh so it is really like that. Thanks mate.