fuzzybinary / fuzzybinary/godot_dart

`convertFromVariant` can crash when in an invalid object

Open
#26 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
203
Forks
10
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the generated Array indexed getter and setter, convertFromVariant, and Variant construction, including the GodotObject TypeInfo path. Reproduce conversion from an invalid object and verify that indexed access avoids the extra Variant conversion, rejects Variant-wrapping, and no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, godot
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.