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"

Why is a simple function crashing the editor?

Its been a while since I did any C++ but I can't see why this is happening;

I've added a few lines of code to the character class;

This is in the header file;

       /** Function for deleting hand hold from currently active hand-hold info */
     UFUNCTION(BlueprintCallable, Category=Inventory)
     TArray <float> DeleteHandHold( TArray <float> HandHold, TArray <float> ActiveHandHolds);
 
 private:
 
     bool findHandHold(TArray<float> HandHold, TArray <float> TestHandHold);
 
 };

This is in the cpp;

 // function to sort array, find handhold and delete it, return the new array
 TArray <float> ALedgeGrabCharacter::DeleteHandHold(TArray<float> HandHold, TArray <float> ActiveHandHolds)
 {    
     int AHHSize = ActiveHandHolds.Num();
     int loopNum = AHHSize;
     for (int i = 0; i < loopNum / 6; i += 6) {
         TArray<float> TestHandHold;
         for (int y = i; y < 6; i++) {
             TestHandHold.Add(ActiveHandHolds[y]);
         }
         if (findHandHold(HandHold, TestHandHold) == true) {
             for (int x = 0; x < 6; x++) {
                 if (ActiveHandHolds.Num() > 0) {
                     ActiveHandHolds.RemoveAt(i);
                     break;
                 }
             }
         }
     }
     return ActiveHandHolds;
   }
 
 bool ALedgeGrabCharacter::findHandHold(TArray<float> HandHold, TArray <float> TestHandHold) {
     
     if (HandHold[0] == TestHandHold[0] && HandHold[1] == TestHandHold[1] && HandHold[2] == TestHandHold[2] && HandHold[3] == TestHandHold[3] && HandHold[4] == TestHandHold[4] && HandHold[5] == TestHandHold[5]) {
         return true;
     }
     else return false;
 }

This is how the function node is being using in BP. Its being fired by an end overlap event in the HandHold BP. Anyone see what I've done wrong? Many thanks!

alt text

Product Version: Not Selected
Tags:
screengrb4.jpg (388.7 kB)
more ▼

asked May 26 '14 at 07:49 PM in C++ Programming

avatar image

robbiecooper
756 79 60 233

avatar image AnxGotta May 26 '14 at 08:07 PM

The log might contain some information about why the editor is crashing. If you go to your project directory, navigate to Saved > Logs > LOGOFCRASH.log and open that up, the answer might be there. If not, what does the error say?

avatar image robbiecooper May 26 '14 at 08:29 PM

Hmm. There's no log named that way in the saved > logs file. There's a bunch of Dump files with "Exception Information: The thread tried to read or write to a virtual address for which it does not have appropriate access." No error message, the game just hangs and then the editor crashes.

avatar image AnxGotta May 26 '14 at 08:33 PM

I apologize, I wasn't clear about the log name, that name I put in there was just a place holder.

alt text

You would simply select the most recent log after you experience a crash in the editor and open it in word.

logs.png (28.8 kB)
avatar image robbiecooper May 26 '14 at 08:32 PM

I just did it again and there's a new dump file there, timed at when I did it...

avatar image Shadowriver May 26 '14 at 08:35 PM

Run editor on debugger it should point you to line that crashes the editor

avatar image robbiecooper May 26 '14 at 08:59 PM

Cool, thanks, good debugging tools, hadnt used them yet...

avatar image robbiecooper May 26 '14 at 09:14 PM

That worked well, thanks! The problem with what was getting sent to it- made the function go out of bounds on the array, I think.

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

1 answer: sort voted first

Never Assume Length

You are consistently assuming array lengths!

  int AHHSize = ActiveHandHolds.Num();
     int loopNum = AHHSize;
     for (int i = 0; i < loopNum / 6; i += 6) {
        TArray<float> TestHandHold;
        for (int y = i; y < 6; i++) {
          TestHandHold.Add(ActiveHandHolds[y]);
        }

You should never assume length!

IsValidIndex()

Use IsValidIndex() to ensure that all your index arithmetic and assumptions did actually pan out correctly.

 if(ActiveHandHolds.IsValidIndex(y))
 {
   //safe to access the index
   ActiveHandHolds[y] = //etc
 }


Never Use Int

  int AHHSize = ActiveHandHolds.Num();

use int32

 int32 AHHSize = ActiveHandHolds.Num();

Rama

more ▼

answered May 27 '14 at 02:01 AM

avatar image

Rama
10.6k 446 343 1085

avatar image Acren May 27 '14 at 02:32 AM

Why never use int?

EDIT: Got it. "Don't use the C++ int type in portable code, since it's dependent on the compiler how large it is." That's useful to know.

avatar image robbiecooper May 27 '14 at 08:39 AM

Hey Rama That's useful to know, I agree! Also IsValidIndex(), thanks alot!

avatar image samnater Dec 01 '18 at 12:45 PM

Thanks Rama! Love your work! Keep on keeping on!

This fixed an issue for me where online multiplayer was crashing the game--whereas local multiplayer and single player did not show any issues. If you check your logs you may find this error message:

LogScriptCore:Warning: Script Msg: Attempted to access index 0 from array EnemiesWithinRange of length 0!

(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