TheParadox
(TheParadox)
December 31, 2017, 12:04am
1
Greetings,
So I am currently trying to load a list of individuals from a .csv file.
Now it loads everything fine, displays it correctly in the debug log HOWEVER, it always crashes when I attempt to put it in an FString.
csv is formatted as such, was created and saved with Excel:
firstName, middleName, lastName, date, month, year
Code:
TArray<FString> AFileHandler::LoadIndividualsFile() {
TArray<FString> data;
FString temp;
FString fileLocation = "C:\\FULLPATH-HERE-FOR-TESTING-PURPOSES-ONLY\\Data\\testIndividuals.csv";
TArray<FString> fromFile;
FFileHelper::LoadANSITextFileToStrings(*fileLocation, NULL, fromFile);
for (int i = 0; i < fromFile.Num(); i++) {
FString aString = fromFile[i];
TArray<FString> stringArray = {};
aString.ParseIntoArray(stringArray, TEXT(","), false);
for (int j = 0; j < stringArray.Num(); j++) {
UE_LOG(LogTemp, Warning, TEXT("%d == %s"), j, *stringArray[j]);
}
temp = stringArray[2]; // <--- this breaks it
//temp += stringArray[0] + " ";
//temp += stringArray[1];
//data.Add(temp);
}
return data;
}
I want to display the name in: Last, First Middle - hence the three lines for it
It always crashes when I attempt to put stringArray[someIndex] into a FString (or add it to data for that matter), however the log works fine.
From all the examples I have see this should be working.
Any ideas on what I am doing wrong?
Thanks!
xlar8or
(xlar8or)
December 31, 2017, 12:14am
2
Hey there, what is the error you are getting? You might be accessing an invalid position, first check what is stringArray.Num() to see if it’s parsing correctly.
TheParadox
(TheParadox)
December 31, 2017, 12:17am
3
I do, at line 17 - I iterate through stringArray and display the contents to the log - So there is a value there and I see it in the log.
The issue is getting that value into another FString
TheParadox
(TheParadox)
December 31, 2017, 12:19am
4
Oh, also I am not getting an error, the editor just crashes.
TheParadox
(TheParadox)
December 31, 2017, 12:22am
5
Hmm… okay that is odd.
This works
for (int j = 0; j < stringArray.Num(); j++) {
temp += stringArray[j];
}
This does not
temp = stringArray[2] + ", ";
//temp += stringArray[0] + " ";
//temp += stringArray[1];
TheParadox
(TheParadox)
December 31, 2017, 12:23am
6
Formatting issues…
Works
for (int j = 0; j < stringArray.Num(); j++) {
UE_LOG(LogTemp, Warning, TEXT("%d == %s"), j, *stringArray[j]);
}
Doesn’t
temp = stringArray[2]; // + ", ";
temp += stringArray[0] + " ";
temp += stringArray[1];
TheParadox
(TheParadox)
December 31, 2017, 12:25am
7
Please ignore some comments, could not get the code sections to work, or edit/remove comments for that matter
After some additional Testing:
This works
for (int j = 0; j < stringArray.Num(); j++) {
temp += stringArray[j];
}
TheParadox
(TheParadox)
December 31, 2017, 12:25am
8
But this does not
temp = stringArray[2] + ", ";
temp += stringArray[0] + " ";
temp += stringArray[1];
TheParadox
(TheParadox)
December 31, 2017, 12:26am
9
temp = stringArray[2] + ", ";
temp += stringArray[0] + " ";
temp += stringArray[1];
xlar8or
(xlar8or)
December 31, 2017, 2:22am
10
Have you tried stringArray[index].Append ?
TheParadox
(TheParadox)
December 31, 2017, 3:19am
11
temp.Append(stringArray[index]);
and
stringArray[index].Append(temp);
Both cause the editor to crash.
xlar8or
(xlar8or)
December 31, 2017, 2:12pm
12
If you print stringArray.Num() what do you get?
TheParadox
(TheParadox)
December 31, 2017, 7:06pm
13
if(GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::Printf(TEXT("%d"), stringArray.Num()));
Prints: 6
for (int j = 0; j < stringArray.Num(); j++) {
UE_LOG(LogTemp, Warning, TEXT("%d == %s"), j, *stringArray[j]);
}
Prints:
0 == firstname
1 == middlename
2 == lastname
3 == day
4 == month
5 == year
UE_LOG(LogTemp, Warning, TEXT("%d"), stringArray.Num());
prints: 6
xlar8or
(xlar8or)
January 1, 2018, 9:46pm
14
It seems to be printing fine, if after that for loop you do:
FString first = stringArray[0];
Does it crash? If it does, what is the error? Try this as last resort:
FString second = FString::Printf(TEXT("%s"), *stringArray[0]);
TheParadox
(TheParadox)
January 2, 2018, 3:19am
15
Neither worked. Both crashed the editor - in the error log everything looks good up to the last two entries.
[2018.01.02-03.11.31:798][484]LogOutputDevice:Warning:
Script Stack:
ManagerBP_C.RetriveListOfItems
MainWidgetBP_C.ExecuteUbergraph_MainWidgetBP
MainWidgetBP_C.BndEvt__IndividualsButton_Button_K2Node_ComponentBoundEvent_526_OnButtonClickedEvent__DelegateSignature
[2018.01.02-03.11.31:802][484]LogWindows: Windows GetLastError: The operation completed successfully. (0)
xlar8or
(xlar8or)
January 2, 2018, 11:44am
16
Send the entire c++ call stack.
TheParadox
(TheParadox)
January 2, 2018, 5:00pm
17
Okay, how do I do that… quick google search (unless I used the wrong terms) does not work for me
xlar8or
(xlar8or)
January 2, 2018, 5:27pm
18
If you execute the editor using visual studio it will stop execution before crashing and below you should have a panel called call stack like this , check that and either copy all the lines or send a screenshot.
xlar8or
(xlar8or)
January 2, 2018, 6:48pm
20
That’s not it, you have to select the call stack option on the bottom.