Editor crashing when using a bindAction

Hi, i recently created a code that is supposed to switch the view mode of the player (First Person, Third Person)
When i press the key in game, the editor crashes, so i cant see any errors and the code compile correctly.
the code below is the functions i created for this.

PlayerInputComponent->BindAction("SwitchViewMode", IE_Pressed, this, &AsurviveCharacter::SwitchViewMode);
    void AsurviveCharacter::SwitchViewMode()
    {
    	if (getCurrentViewMode() == viewModes::FirstPerson)
    	{
    		SwitchViewMode(viewModes::ThirdPerson);
    	}
    	else
    	{
    		SwitchViewMode(viewModes::FirstPerson);
    	}
    }
    
    void AsurviveCharacter::SwitchViewMode(viewModes vm)
    {
    	if (vm != getCurrentViewMode())
    	{
    		if (vm == FirstPerson)
    		{
    			bUseControllerRotationPitch = false;
    			bUseControllerRotationYaw = true;
    			bUseControllerRotationRoll = true;
    
    			desiredArmLength = 0.f;
    
    			CameraBoom->AttachTo(ACharacter::GetMesh(), "headSocket");
    		}
    		else
    		{
    			bUseControllerRotationPitch = false;
    			bUseControllerRotationYaw = false;
    			bUseControllerRotationRoll = false;
    
    			desiredArmLength = 300.f;
    
    			CameraBoom->SetupAttachment(RootComponent);
    
    			
    		}
    	}
    	
    }
    
    int AsurviveCharacter::getCurrentViewMode() const
    {
    	if (desiredArmLength < 50.f)
    	{
    		return viewModes::FirstPerson;
    	}
    	else
    	{
    		return viewModes::ThirdPerson;
    	}
    }
    void AsurviveCharacter::Tick(float DeltaTime)
    {
    	Super::Tick(DeltaTime);
    	if (desiredArmLength > CameraBoom->TargetArmLength)
    	{
    		CameraBoom++;
    	}
    	else if (desiredArmLength < CameraBoom->TargetArmLength)
    	{
    		CameraBoom--;
    	}
    }

Help !!

You should be able to get more information on the crash - for instance output, or a callstack.

If you are on PC, run the game from Visual Studio in “DebugGame Editor” mode and you should get more information. The only thing that stands out is you are not checking CameraBoom against nullptr.

Hey Holiska-

As mentioned, it might be helpful to check your CameraBoom pointer to ensure it that it is not a null value. Additionally, running the program from Visual Studio (F5 by default) should tell you where the crash is occurring as well as provide the callstack from the crash. Please let us know if you’re able to gather any additional information about the crash.

I created a breakpoint on Tick, and and some times when tick is executed, CameraBoom’s value is equal to “0x0000027e2c499d30 (Name=Invalid)”, and when i check cameraboom against nullptr it still crash, but some times i can
press the key without crashing,i think the editor crash when i press the key when cameraboom’s name is Invalid.
I don’t know how i could fix it.

now when i create a breakpoint on the CameraBoom->AttachTo(ACharacter::GetMesh(), "headSocket");
it throw an exception :

"Unhandled exception at 0x00007FF8D800B4DA (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

this look like a nullptr, but i have a nullptr check just above it.

Do you get a callstack in visual studio when the breakpoint is triggered? If so, please post the full callstack. Additionally, does the crash occur when switching from a specific view or does it happen which switching from either view. For example, does the crash only occur when switching from First to Third person, or does it occur for going from Third to First as well?

The editor crash every time i press the key and visual studio show me this error

"Unhandled exception at 0x00007FF8D325B4DA (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

If there is a handler for this exception, the program may be safely continued.

"

i removed the desiredArmLength variable and the tick function and now i set cameraboom’s target arm length directly, it was only esthetic, now it doesn’t crash anymore.
Thank you for your help, i didn’t now that we could debug with unreal engine, and the problem was CameraBoom as you said.