When i start eu4 it crashes

When I try to start UE4 Project it crashes can u help me, guys. I don’t know what to do.
Crashes and Logs: File upload and sharing. Large file transfers. Free online cloud storage.
I uploaded both crashes and logs. I can’t even start the project to see the error.

at files.FM I uploaded win rar… but if u want to be safe and u think its virus I uploaded to google drive too.

Crashes: Crashes - Google Drive
Logs: Logs - Google Drive

i am using latest ue4 version

Hey there, if you check the last log you will see that the crash comes from:

[Callstack] 0x00000000EDF35227 UE4Editor-MyProject3-4829.dll!UOpenDoorC::UOpenDoorC() [c:\users\luka\documents\unreal projects\myproject3\source\myproject3\opendoorc.h:34]

Can you show me the code near that line in the header? If you are using c++ then i would suggest launching the editor with visual studio so that when it crashes it goes to line of the problem with more information instead of just giving the crash report screen.

Hi… Thanks for reply… :slight_smile:
/*
Can you show me the code near that line in the header? If you are using c++ then I would suggest launching the editor with the visual studio so that when it crashes it goes to the line of the problem with more information instead of just giving the crash report screen.

so if I start the first visual studio and then ue4. will it show me error line?
thanks for the tip.
*/
here is the code

link text
link text

You can’t do this in a header file:

AActor* Owner = GetOwner();
AActor* ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
    
FRotator Rotation = Owner->GetActorRotation();

These are operations that should be done during runtime in the cpp. Try this:

.h

AActor* Owner;
AActor* ActorThatOpens;
FRotator Rotation;

virtual void BeginPlay() override;

.cpp

void AYourClassName::BeginPlay()
{
    Super::BeginPlay();

    if(GetWorld() != nullptr)
    {
         Owner = GetOwner();

         if(Owner != nullptr)
              Rotation = Owner->GetActorRotation();

         ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
    }
}

Are there any reasons why I cant use those variables in .h?

You can define them but you can’t set it to values that can’t be computed at construction time. That’s why i moved the setting of the values to BeginPlay().

Can you tell me why? or just give me the link to read some information about this issue, because in c++ its possible to use something like this I think.

I just gave you the reason :stuck_out_tongue: GetOwner() and GetWorld() i believe only exist during runtime, so when you are still creating the objects they don’t exist yet. Not to mention it’s good practice to do safety checks to see if they valid and you can’t do that in the .h (unless it’s a function).

good answer thanks. and can u tell me how to do safety checks to see if they are valid (in functions)

I edited my example code to include some simple safety checks. This is just a guideline, but it’s not protecting against everything, if there is no player controller it would crash on GetWorld()->GetFirstPlayerController().

thanks for good answer again… so i have to check for everything like this?

if (GetWorld()->GetFirstPlayerController())
{

}

That works, although i like to explicitly use:

 if (GetWorld()->GetFirstPlayerController() != nullptr)
 {
 
 }

So I have to check every time if I have the null pointer for safety. is there any better way to check that?
So what about the blueprint. Do I have to use "if"s in blueprints too (for safety)?

Yes if you want to make sure your code is mostly protected, but usually people find a balance between the areas you do the checks, so in certain areas where you are pretty sure it has a valid value then you don’t use it. Doing safety checks for everything consumes developer time and game performance aswell if you use them a lot, although obviously its better to be slow than to crash. In the prototype i’m doing, since it’s not going to be played by anyone other than my team i use the minimum amount of checks to not crash, but if it was for someone to play it i would probably add a bit more checks, but i would still not test everything.

Do I have to use "if"s in blueprints too (for safety)?

Yes i use Is Valid macro.

Good answers… Thanks

You are welcome :slight_smile:

by the way which one is the correct form to check about pointer validity
ptr==0;
ptr==NULL;
ptr==nullptr;

is there any difference?