x

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"

Access violation error when I try to access my the TeamScore array in GameState in HUD

My goal here is to set a HUD object to show a team score. I can access my GameState class but when I try to get a value from my TArray TeamScores the editor crashes and gives me "Access Violation - code c0000005 (first/second chance not available)". TeamScores is public in the GameState header. I'm using version 4.4.3. This is the code in the HUD that is causing the crash or at least what the crash report is pointing too, which is the second line.

 AFPSGameState* GS = Cast<AFPSGameState>(GetWorld()->GameState);
 const int32 VirusScore = GS->TeamScores[0];

Does anybody know why it is crashing?

Product Version: Not Selected
Tags:
more ▼

asked Dec 08 '14 at 12:48 AM in C++ Programming

avatar image

zehnpfennigb
6 1 2 3

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

You need to test that the AFPSGameState pointer is valid after the cast:

 AFPSGameState* GS = Cast<AFPSGameState>(GetWorld()->GameState);
 const int32 VirusScore;
 if (GS != nullptr) {
    VirusScore = GS->TeamScores[0];
 }
more ▼

answered Dec 08 '14 at 02:03 AM

avatar image

ogrewizardninja
136 2 4 16

avatar image zehnpfennigb Dec 08 '14 at 03:36 AM

Thanks that fixed that problem. Now it is saying that TeamScores[0] is out of bounds.

avatar image ogrewizardninja Dec 08 '14 at 05:18 AM

Can you post the code where you create and initialise your array? An error like that usually means you haven't correctly sized your array.

avatar image zehnpfennigb Dec 08 '14 at 05:37 AM

I figured it out. I forgot to initialize the array so there wasn't actually anything in there. Thank you for your help though!

(comments are locked)
10|2000 characters needed characters left
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