ilanegra
(ilanegra)
November 21, 2017, 9:21pm
1
Hello i have a part of code and want the engine to stop runtime and send an error line instead of crashing when affected object does not have a UAROTARGET component.
The code is: c
UActorComponent* tempTargetComp;
for (int object = 0; object < affectedObjects.Num(); ++object) {
tempTargetComp = affectedObjects[object]->GetComponentByClass(UAROTarget::StaticClass());
if (tempTargetComp != nullptr) {
targetAROComponent[object] = dynamic_cast<UAROTarget>(tempTargetComp);
}
}
c4tnt
(c4tnt)
November 21, 2017, 10:35pm
2
Hi. This code will show a message and close a game then.
const FText Message = ...Your message...
FMessageDialog::Open(EAppMsgType::Ok, Message); // Show message
FPlatformMisc::RequestExit(false); // Exit application
ilanegra
(ilanegra)
November 22, 2017, 12:38am
3
The problem i have is the crash just when runtime starts that Beginplay() is running on all scripts
c4tnt
(c4tnt)
November 22, 2017, 5:34am
4
Sorry. If it crashes try to use Cast<…>() instead of dynamic_cast
ilanegra
(ilanegra)
November 22, 2017, 7:14am
5
No luck either, code now looks like this:
tempTargetComp = affectedObjects[object]->GetComponentByClass(UAROTarget::StaticClass());
if (tempTargetComp != nullptr) {
targetAROComponent[object] = Cast<UAROTarget>(tempTargetComp);
if (targetAROComponent[object] == nullptr) {
FPlatformMisc::RequestExit(false);
}
} else {
FPlatformMisc::RequestExit(false);
}
But the problem is doesnt matter if i exit with or without finishing the loop it crashes because it tries to do at leats once the update (and because of code and arrays and stuff in cant do the update correctly if there is a nullptr in the array)
c4tnt
(c4tnt)
November 22, 2017, 7:56am
6
Maybe it crashes on a first line, where you using affectedObjects[object] without any checks.