Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why does my game crash after running fine?

So I'm adding a teleport mechanic to the Shooter game in Unreal Engine.

When I play the game, I can teleport correctly and it seems to be running fine. But after maybe two minutes, all of a sudden it crashes when I try to teleport. Keep in mind, this is after teleporting all over just fine. The call stack from the crash points me to either a FHitResult or a line with the expression: rayFather->fDropDepth

Right now I have the following:

 FHitResult newHitHolder(ForceInit);

 FVector vecLowestDropDir;

 vecLowestDropDir = FVector(ForceInit);

 vecLowestDropDir = FVector(0, 0, -rayFather->fDropDepth); /*This is the line that crashed it most recently!*/

 FVector vecPointEnd = vecOrigin + (vecLowestDropDir * rayFather->fDropDepth);

I should also mention that I have no idea what ForceInit does or is and can't find any information on in anywhere but I see it being used all over in other people's code so I gave it a try. Those first four lines used to just read:

 FHitResult newHitHolder;

 FVector vecLowestDropDir = FVector(0, 0, -rayFather->fDropDepth);

I've used other FHitResults in places without any ForceInit and it works fine! And I use FVectors all over without ForceInit with no problems! Other things that might be helpful: -The code given runs several times in a for loop whenever a teleport is being aimed. -The code provided runs from a UDataAsset. -The data assets are basically two different nodes that work as a head and a tail to find the most desirable teleport spots along a ray. They are managed by an USceneComponent that attaches to the player controller. -rayFather refers to the scene component. The data assets refer to the scene component to get the desired drop depth. So rayFather->fDropDepth should retrieve the scene component's fDropDepth. And it does! Because teleporting works! Until it doesn't. -The scene component and data assets are created and linked at the start of the game and neither of them are ever being destroyed.

Any ideas? I've been battling this for a good amount of time now and I'm completely out of ideas. I feel like knowing what ForceInit actually does might help but something tells me the problem is more involved than that...

Product Version: UE 4.15
more ▼

asked Jul 20 '17 at 12:40 AM in C++ Programming

avatar image

1 1

avatar image Nachtmahr Jul 20 '17 at 04:06 AM

Would be nice if you can share a bit more Code around it, would be nice to know where you Pull the Obj from and if you Cast it correctly. Aswell as the full Stacktrace. You can do a if(rayFather) around your whole block of Code.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

ForceInit does something with FMemory, which I am not familiar with. My guess is that it loads something into memory (the FHitResult struct) and sets the initial time variable in the FHitResult struct to 1. As far as I know, you can technically use it without ForceInit, but that's pretty much all I know about it.

Anyway, as for your problem, if the rayfather variable is a scenecomponent and it happens to crash on that line, my guess is that it is NULL at the point you are calling it. I know you mention that it isn't being destroyed anywhere, but it could very well be that the variable is not being initialized properly. Perhaps you should put a NULL test in there. Also, where are you finding DropDepth? I have looked through the classes, but I cannot find that variable anywhere in the sourcecode, let alone in scenecomponent or any of the classes it's based on.

more ▼

answered Jul 20 '17 at 01:49 AM

avatar image

815 30 26 105

avatar image caleb.tenebrous Jul 20 '17 at 02:15 AM

I do a null test right before that section:

     print("rayFather is null!"); // This is a macro that uses on-screen debug messages

That IS a correct null test is it not?

Also, I should have been clearer in the original post. fDropDepth is my own variable. It is a member of rayFather. It's public and non-const as well. In the BeginPlay method fDropDepth is set to MyParentalCharacter's fTeleportRange / 2.

I also had it log the value of rayFather->fDropDepth to the screen. It logged as 2000.0f each time it was referenced. Until it crashes.

The exact message it gives me is:

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

From everything I can see online, this is supposedly a null pointer error. But I test it for null... And it's not... Unless I'm testing it wrong? Is there a way to make the game pause and step through the code as it runs it? That would be so much better than crashing the whole thing each time. I've tried debugging with break points but I'm not sure how that interfaces with Unreal and can't seem to get it to do anything. Does visual studio have to be in a certain configuration?

avatar image cridia Jul 24 '17 at 03:47 AM

It seems you have the null test there, so I am confused as well. Would it be possible to share the involved classes somewhere so I can have a better look? If you don't want to share it here, you can also send it to my gmail (right there in my account).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question