Access violation in Editor

Hi there hope someone can help me , i build my code , all worked fine and as expected , and once i hit play there was an access violation error.

I sent the bug report already.

and in visual studio this message came up :

Unhandled exception at 0x00007FF9BC45BB0E (UE4Editor-MyProject.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000370.

Any solutions
Thanks

Forgot to mention , im using 4.5 version

This by itself tells nothing. What does the stack trace looks like, on what line does it crash when debugging in Visual Studio?

From that stack, you can clearly see that you have an error at line 20 of your weapon.cpp file.

In the Fire() function.

If you paste your code from that function I may be able to help further, but this looks like an access to an invalid object…

It debugs visual studio , when i hit play butn in editor , the error message comes up i send the bug report , and then when i came back to visual studio thats what appeared. Also there are no errors on the code , as far as i know

Would this help ?

MachineId:063E2EFC4BA7A923233E70B105319923
EpicAccountId:

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

UE4Editor_MyProject!AWeapon::Fire() + 30 bytes [c:\users\rui\documents\unreal projects\myproject\source\myproject\private\weapon.cpp:20]
UE4Editor_Engine + 15815490 bytes
UE4Editor_Engine + 6411406 bytes
UE4Editor_Engine + 6464208 bytes
UE4Editor_Engine + 6402091 bytes
UE4Editor_Engine + 6462880 bytes
UE4Editor_Engine + 1652387 bytes
UE4Editor_Engine + 8779958 bytes
UE4Editor_Engine + 8829659 bytes
UE4Editor_Core + 746772 bytes
UE4Editor_Core + 747165 bytes
UE4Editor_Core + 870341 bytes
UE4Editor_Engine + 9060549 bytes
UE4Editor_Engine + 8971673 bytes
UE4Editor_Engine + 8982533 bytes
UE4Editor_Engine + 5590422 bytes
UE4Editor_Engine + 5619151 bytes
UE4Editor_UnrealEd + 1895346 bytes
UE4Editor_UnrealEd + 6486374 bytes
UE4Editor!FEngineLoop::Tick() + 3524 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launchengineloop.cpp:2129]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launch.cpp:133]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:201]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

Well i belive its an invalid object cause the code i have is pretty simple , and before the error came up , i had tested this part of code and it was working fine

void AWeapon::Fire()
{
	if (ProjectileType == EWeaponProjectile::Ebullet)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
		Instant_Fire();
	}
	if (ProjectileType == EWeaponProjectile::ESpread)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
		for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++)
		{
			Instant_Fire();
		}
	}
	if (ProjectileType == EWeaponProjectile::EProjectile)
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));
}

this is the line 20

if (ProjectileType == EWeaponProjectile::Ebullet)

From what you tell me, this happens as soon as you hit Play, which is strange since you should not be calling Fire() at that moment. If this is indeed the case, your Fire() is probably being called at a moment where GEngine is not yet valid, which is strange.

Which line is line 20?

Also, try adding this at the beginning of the function and see if it works:

if(!GEngine)
    return;

Then there is an issue with ProjectileType. I’m assuming this is an enum, how is that enum declared in your weapon.h file? I’m thinking you may have missed the UPROPERTY() macro ?

That or the stack indicate that line and may have crashed on the other one, try if(!GEngine) return; jus tto be safe too.

I have to leave for the night, but here is the proper way to declare an enum, since it looks like that may be the problem here:

UENUM()
enum EWeaponProjectile
{
	EBullet,
	ESpread
	EOtherType,
	EOtherType02
};

//And here how to add a member of that type in your .h 
UPROPERTY()
TEnumAsByte<EWeaponProjectile> ProjectileType;

Right at the start of the function :

void AWeapon::Fire()
 {
     if(!GEngine)
           return;

     if (ProjectileType == EWeaponProjectile::Ebullet)
     {
         GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
         Instant_Fire();
     }
     if (ProjectileType == EWeaponProjectile::ESpread)
     {
         GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
         for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++)
         {
             Instant_Fire();
         }
     }
     if (ProjectileType == EWeaponProjectile::EProjectile)
         GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));
 }

so where would i put this

if(!GEngine)
return;

Exactly ?

i got this Enum :

UENUM(BlueorintType)
namespace EWeaponProjectile
{
	enum ProjectileType
	{
		Ebullet			UMETA(DisplayName = "Bullet"),
		ESpread			UMETA(DisplayName = "Spread"),
		EProjectile		UMETA(DisplayName = "Projectile"),
	};
}

and also the UPROPERTY :

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Config)
		TEnumAsByte<EWeaponProjectile::ProjectileType> ProjectileType;

But i know that the code i have , is not the problem :x

Last successfull build i had , i was able to walk around shoot etc…
So the problem isnt on the code itself .

Here is a video tutorial , i was following, at minute 13 ± thats where i crash .

And if u check the video commentaries u see that someone else had the same problem as me

Its a long video , just need to watch until minute 13 ( if ur intrested ofc)

And thx for the quick replys

This is weird:

UENUM(BlueorintType)
 namespace EWeaponProjectile
 {
 }

I don’T know if it’s a typo, but it should be “BlueprintType”, not “BlueorintType”

fixed it , wasnt the problem + didnt give me an error somehow :expressionless:

also i made that gengine and didnt work aswell