Don't Understand Access Violation - c0000005 (first/second chance not available)

For one of my projects, I eventually got to a point where I would keep getting this error whenever I try to open the project:

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

""

UE4Editor_FightTheSwarm_2384!ARockEnemy::ARockEnemy() [c:\users\zane\documents\unreal projects\fighttheswarm\source\fighttheswarm\rockenemy.cpp:10]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\coreuobject\private\uobject\class.cpp:2657]
UE4Editor_CoreUObject!UObjectLoadAllCompiledInDefaultProperties() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:729]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:815]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance::ExecuteIfSafe() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:921]
UE4Editor_Core!TBaseMulticastDelegate::Broadcast() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:809]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\modules\modulemanager.cpp:426]
UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\projects\private\moduledescriptor.cpp:370]
UE4Editor_Projects!FProjectManager::LoadModulesForProject() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\projects\private\projectmanager.cpp:53]
UE4Editor!FEngineLoop::LoadStartupModules() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\launchengineloop.cpp:1989]
UE4Editor!FEngineLoop::PreInit() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\launchengineloop.cpp:1495]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\launch.cpp:110]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]

I’ve looked at other posts about this error, but it doesn’t seem like they are relevant to me. What is the general cause of this error? I can see that it refers to a line in my code, but I don’t understand why that code is the point of error.

I tried commenting it out in a text editor and opening the project again, but I still got the same error. I also tried moving some of the files related to this class (things about “RockEnemy”), but there was no effect.

The general cause of this error is a null pointer ( I won’t go into the LGT and GDT, nor page tables etc, that it actually stems from). In your code check the pointer var against “NULL” or “nullptr”, so you can see what is going on.

so assuming something like

sometype* myptr;

if (myptr == nullptr) {
hollerReallyLoud “Houston we have a problem”;
}

.

I agree with . That is definitely the usual cause of access violations. From the callstack you provided it seems like it’s something related to your constructor for ARockEnemy and in particular something that is being initialized with CreateDefaultObject().

If there isn’t much code there, a good way of debugging it would be to comment out lines of code until you can narrow down what is causing the issue, especially when you’re completely lost as to what is wrong.

If that doesn’t help, would you be willing to post the code for that class so that we can take a look?

Since the error makes it so I can’t even open the project, will the files I modify be recompiled? I tried commenting out the line in ARockEnemy where this occurs (line 10), and it still got the exact same error. Here are the relevant files from this project:

Let me know if the link doesn’t work or you need more. Thanks.

Any changes you make to the code and compile should be reflected in the editor. To ensure that this is entire thing is the code issue, you could go as far as to comment out the entire files for the custom classes you added (leave the original source files as they were) and then compile.

The link you provided seems to not work, as it doesn’t direct to a page with a download button.

Will the project compile on its own, or do I have to run a compile in the editor? Since the project crashes whenever I try to open it, I can’t compile through the editor.

See if this link works:

Any time you compile inside of Visual Studio, it updates the files that the editor is depending on to run. Even when you compile from inside of the editor, Visual Studio is doing all of the work to compile it and then giving the editor the updated files.

That download link works, I’ll take a look and let you know if anything seems out of place but debugging on your end should help narrow it down as well.

By the editor, do you mean the Visual Studio editor or the Unreal Engine editor? If I understand you correctly, are you saying I can compile in Visual Studio without opening the Unreal Engine editor? Thanks.

The Unreal Engine Editor does not need to be open the compile the project in Visual Studio.

It seems like the issue could be something to do with your blueprints based off these classes rather than the classes themselves. I created a new project, added the classes that you gave me and everything compiles fine and the editor doesn’t crash. Could you try opening the Content folder for your project, finding any blueprints you had made based off these classes and cut/paste them to another directory out of your project so that you can temporarily remove them and see if the crashes still occur?

I commented out the exact line of the error and compiled in Visual Studio, but it still said it got an error at the exact same place. I also tried removing all the blueprints from my blueprints folder, and the same thing still happened. Could the error be somewhere else even though it says it’s line 10 of RockEnemy.cpp?

After commenting out that line, Visual Studio should at least be pointing to another part of your code. Is it giving you a different error after you comment out that line of code? Would it be possible for you to upload a copy of the project so that I can take a look into what is wrong?

No, it gives the same error after I comment out that line. See if you can access the project at this link:
https://onedrive.live.com/redir?resid=7AAE9EA4B5726552!15133&authkey=!AO5wjg700YsAlh4&ithint=folder%2Cmd

Thank you for the project. I downloaded it but I’m not getting the access violation that you were running into, although I do get quite a few errors/warnings in the output log when opening the project. The fact of me being able to open the project could be related to how I downloaded it. Can you try deleting your Binaries and Intermediate folders, along with the .sdf file in your project’s directory? After that, right-click the .uproject file and Generate Visual Studio Project files. This will repopulate some of the intermediates and remake the .sln. After that, open up the .sln and build the project. Once that completes, try opening the project to see if you get the same issue.

I did all that and now I can get into the project. Thank you very much!

Umm… can I contribute a possible solution? I had this problem too (my project would initialize until 73% then crashes immediately), with UE 4.14.3

If we look at the first few lines…

Access violation - code c0000005 (first/second chance not available)
UE4Editor_FightTheSwarm_2384!ARockEnemy::ARockEnemy() [c:\users\zane\documents\unreal projects\fighttheswarm\source\fighttheswarm\rockenemy.cpp:10]
[…]

Note the "UE4Editor_FightTheSwarm_2384!ARockEnemy[…]

If we go to the project folder i.e. Documents/UnrealProjects/FightTheSwarm/ …in the Binaries/Win64/ folder we will find something like UE4Editor-FightTheSwarm-2384.dll and UE4Editor-FightTheSwarm-2384.pdb

Honestly I have no idea what these files are, but deleting them enabled me to open my project (no more stuck at 73%!). Hope this helps someone out there!

Hello Hariantow,

This is the same thing that I suggested, just in a more specific sense. The .dll and .pdb files are the files created by Visual Studio when the project is compiled. These are what contain almost all of the compiled data for the project. Deleting these should be the first go-to when getting issues like this as it’s simple to do.

Ah, so that’s why a couple days ago I had to delete them even AFTER changing the code in Visual Studio (that is most likely the source of problem). Thanks for clearing that up!

Hello, i have checked your code and it seems you are using GetMesh()->SetSimulatePhysics(true); right onto the initializer of the class aka called Class::Class().

Which will probably return null when you are starting up Unreal Engine, which will then crash the engine after trying to access it.

Please use void Class::BeginPlay()

You can launch Visual Studio with the snl file, edit the code to NOT use the initializer, but the BeginPlay. Then build it via visual studio. Then you can launch the engine.

ONLY use the initializer for setting DEFAULT values.