Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FGResearchTree: Do not crash/assert when reflecting #321

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Th3Fanbus
Copy link
Contributor

Quoting Mircea:

The whole point of validation is to safely validate the data, not
crash if it's invalid.

Replace CastFieldChecked with CastField to avoid asserting when performing data validation. Furthermore, add some NULL checks, some to handle NodeDataStructProperty being NULL, and another to avoid problems if SchematicStructProperty happens to be NULL.

@budak7273
Copy link
Member

Context: the original inspiration for this change was making the Asset Generator not crash when generating trees

Copy link
Member

@mircearoata mircearoata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably return a warning if the validation couldn't be performed because of the invalid class/struct.

It also doesn't try to get the property again on a future attempt if it's still null, so if the class/property is fixed after the first validation, it would still require an editor restart.

In the interest of removing checks from the validation, you could also replace check(ResearchTreeNodeClass).

@Th3Fanbus
Copy link
Contributor Author

Should probably return a warning if the validation couldn't be performed because of the invalid class/struct.

I can't seem to do that because I don't have a validation context in there, just an out parameter for errors. I believe this function signature is deprecated.

It also doesn't try to get the property again on a future attempt if it's still null, so if the class/property is fixed after the first validation, it would still require an editor restart.

Let me see how to handle this. Are these static variables protected against garbage collection? I'm not too fond of having raw pointers.

In the interest of removing checks from the validation, you could also replace check(ResearchTreeNodeClass).

Sounds good.

@mircearoata
Copy link
Member

I can't seem to do that because I don't have a validation context in there, just an out parameter for errors. I believe this function signature is deprecated.

With this old signature the way to do it is to Min/Max the ValidationResult (I forget if Error is the highest or lowest enum value), and add the message to the array.

Are these static variables protected against garbage collection?

AddToRoot stops the thing from being garbage collected, meaning the previous class (if not null) should be removed from root if a new one is loaded instead

@Th3Fanbus
Copy link
Contributor Author

Th3Fanbus commented Nov 15, 2024

I have to use Min because the enum is defined as follows:

enum class EDataValidationResult : uint8
{
	Invalid,
	Valid,
	NotValidated
};

Actually, just noticed that CombineDataValidationResults exists and is immediately below the enum.

Quoting Mircea:

> The whole point of validation is to safely validate the data, not
> crash if it's invalid.

Replace `CastFieldChecked` with `CastField` to avoid asserting when
performing data validation. Also replace one `check` assertion with
a regular NULL check.

For the sake of readability, move the lazy initialisation variables
to helper functions (placed in an anonymous namespace), which fixes
dereferencing possibly NULL pointers. While at it, comment the code
that gets the research tree node class, as it should not be used as
an example on how to do things.

Finally, skip reflection if the research tree has no nodes as there
is nothing to validate.

Signed-off-by: Angel Pons <[email protected]>
@Th3Fanbus Th3Fanbus force-pushed the datavalid-research-treeeeeeee branch from a99b2a1 to 83b21ae Compare November 15, 2024 13:11
}
}
if (!ResearchTreeNodeClass || !NodeDataStructProperty || !SchematicStructProperty) {
ValidationErrors.Add(NSLOCTEXT("ResearchTree", "Validation_ReflectionFailed", "Could not retrieve properties to validate using reflection, validation not performed"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an error. No idea if it will cause problems with the Asset Generator, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would cause any issues, since the asset generator still saves the changes, and nothing should depend on data in the CDO of a research tree.

But the asset generator should also provide the SkipDefaultObjectValidation flag (or something like that) to the blueprint compilation, so that the blueprint is still compiled after every change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mircearoata/UEAssetToolkit#9 should do the skip default object validation, but I haven't tried it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants