Editor crash on simple C++

Project is permanently hosed. It won’t load in the Editor because each time at load, it crashes the Editor.

However, the first crash occurred when I tried to run the project.

Project is very simple - I was doing some simple tutorials and writing some basic C++ code. The crash happened when I tried added the following code:

for (TObjectIterator<UAudioComponent> It; It; ++It)
	{
		UAudioComponent* CurrentObject = *It;
		GEngine->AddOnScreenDebugMessage(-1, 15, FColor::Red, CurrentObject->GetName());
		if (CurrentObject->GetName().Equals(FString("AudioComponent_01"), ESearchCase::IgnoreCase)) {
			fireAudio = CurrentObject;
		}
	}

Then later from a keybinding function (spacebar):

fireAudio->Play();

When I hit spacebar multiple times no sound played. The Editor then crashed and the project refused to load ever since, constantly crashing the Editor.

I realize that fireAudio could have been nullptr or random memory, which should certainly crash the game. Not sure why the project file itself seemed to get into a borked state.

I’ve attached my source files. Everything else is too large.link text

Try next changes:
Make OurCamera as UPROPERTY() pawn variable, I suspect it can be garbage-collected.
Define fire audio like this:

UPROPERTY(VisibleAnywhere)
UAudioComponent * fireAudio = nullptr;

Equate OurVisibleComponent to nullptr as well.
In startGrow do null-check before call:

if(fireAudio) fireAudio->Play();

Any unintialized variable will cause big problems hard to find. If you launched editor in debug then all uninitialized variables will have value 0xcdcdcdcd… what is the easiest way to track them.
UE4 also has Garbage Collector: if it found any data piece, that has no pointer to it then this data will be purged. GC happens at very start of editor (when it shows up) and then every 60 seconds by default. UPROPERTY variables are those that can be tracked by GC, classical pointers are not. So OurCamera will be purged instantly, as well as fireAudio.
And yeah, instead of
for(TObjectIterator It; It; ++It)
you can write
for(auto& audioComponent : TObjectIterator)
It’s way accessible and faster.
After you found your audio component you don’t need to go further in loop, use break to end cycle inside of if field.

Ok, so I made the changes you suggested. When I tried to start the Editor, it asked if I wanted to recover changes from an unsaved map. I clicked, “no” because I didn’t want it to potentially crash again.

Then the Editor started up, but has no reference to my C++ class at all. I guess this is better than nothing - I can at least start the Editor, but is there a way to add references to existing C++ code without creating new classes?

ah, nevermind. I just “Refresh Visual Studio Project” from the File menu.