# Crash in a presumably crash safe code?

**URL:** <https://forums.unrealengine.com/t/crash-in-a-presumably-crash-safe-code/1240335>\
**Category:** AI\
**Tags:** unreal-engine, crash, CPP\
**Created:** [July 26, 2023, 6:36am UTC](https://forums.unrealengine.com/t/crash-in-a-presumably-crash-safe-code/1240335 "2023-07-26T06:36:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkenonSGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/skenonsgames/32/574471_2.png) [@SkenonSGames](https://forums.unrealengine.com/u/SkenonSGames)\
**Post date:** [July 26, 2023, 6:36am UTC](https://forums.unrealengine.com/t/crash-in-a-presumably-crash-safe-code/1240335/1 "2023-07-26T06:36:26Z")

</div>

Let’s start with the code:

```auto
for(const UStaticMeshComponent* comp : meshes)
{
	if(IsValid(comp))
	{
		TArray<FName> sockets = comp->GetAllSocketNames(); <- This line crashes
...

```

This code is located inside the OnConstruction method of an actor, it goes through mesh components in a TArray uproperty called “meshes”, and if they are valid does a few operations on their sockets.

The crash doesn’t happen always, for example simply editing the level, or starting the simulation of that level from the editor is fine. But opening a level that contains instances of this actor from a running game (for example: from a menu button) will cause a crash.  
The crash also happened a few times by simply opening the level in the unreal editor, but this is rare.

Now, to make things even weirder, if i change the if statement to this:

```auto
if(IsValid(comp) && IsValid(this))

```

the crash never happened while opening the level in-game;  
But to make it even even weirder, now it did happen a few times by opening the level in-editor.

What is happening here? Why would a simple getter method, executed on a non-null pointer, to a presumably valid component crash the entire editor? Is this a bug?
