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

convertFromVariant can crash when in an invalid object #26

Open
fuzzybinary opened this issue Oct 31, 2024 · 0 comments
Open

convertFromVariant can crash when in an invalid object #26

fuzzybinary opened this issue Oct 31, 2024 · 0 comments

Comments

@fuzzybinary
Copy link
Owner

Found this when working with the indexing operator in Array. The old code for Array's indexed setter and indexed getter was this:

Variant operator [](int index) {
  final self = Variant(this);
  final ret = gde.variantGetIndexed(self, index);
  return convertFromVariant(ret, null) as Variant;
}

void operator []=(int index, Variant value) {
  final self = Variant(this);
  final variantValue = Variant(value);
  gde.variantSetIndexed(self, index, value);
}

Besides being inefficient, this was causing a crash because (I think) the engine was either mangling some pointers or the token was invalid when trying to convert to an Object.

I've taken the following steps to mitigate:

  • Modified the index getter / setter in the code generation to avoid the extra Variant conversion when the return type is Variant.
  • Avoid a null token when converting a variant to an Object by always passing in the TypeInfo for GodotObject
  • Throw an exception if you try to construct a Variant with a Variant.

However, we should take further steps to ensure this isn't a bigger problem.

fuzzybinary added a commit that referenced this issue Oct 31, 2024
Index getters / setters that return variants were crashing because of a bad attempt to cast the object held in the Variant to an Object.

This may be a bigger issue but it is fixed for arrays.

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

No branches or pull requests

1 participant