Hello everyone. I have a test function on a UObject script that gets called when I press LMB from another script. When I spam click it the game crashes with this:
Exception thrown at 0x000000020000005D in UnrealEditor-Win64-DebugGame.exe: 0xC0000005: Access violation executing location 0x000000020000005D.
Unhandled exception at 0x000000020000005D in UnrealEditor-Win64-DebugGame.exe: 0xC0000005: Access violation executing location 0x000000020000005D.
This happens every time, but I have to spam fire button for about 1 minute for it to crash.
{
FHitResult hitInfo;
if (!PlayerCamera)
{
GEngine->AddOnScreenDebugMessage(-1, 35.0, FColor::Red, "Null Ptr Camera");
return;
}
FVector EndVector = PlayerCamera->GetCameraLocation() + PlayerCamera->GetActorForwardVector() * 900;
bool hitBool = GetWorld()->LineTraceSingleByObjectType(hitInfo, PlayerCamera->GetCameraLocation(), EndVector, ECollisionChannel::ECC_PhysicsBody);
if (hitBool) {
FVector hitPoint = hitInfo.ImpactPoint;
AActor* MyActor = hitInfo.GetActor();
if (MyActor)
{
UStaticMeshComponent* Mesh = Cast<UStaticMeshComponent>(MyActor->GetRootComponent());
if (Mesh)
{
Mesh->AddImpulseAtLocation(PlayerCamera->GetActorForwardVector() * 1500, hitPoint);
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 35.0, FColor::Red, "Null Ptr mesh");
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 35.0, FColor::Red, "Null Ptr actor");
}
}
}
Also VS adds breakpoint symbol to bool hitBool = GetWorld()->LineTraceSingleByObjectType(hitInfo, PlayerCamera->GetCameraLocation(), EndVector, ECollisionChannel::ECC_PhysicsBody);
line after the crash.