Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Mar 1, 2022

Part of flutter/flutter#99347

These errors are detected if you do a build with --dart-debug=true. I would like to try to get this running on CI

@mraleph @mkustermann @a-siva @rmacnak-google fyi

This has no tests, but the plan is to test it by adding a flag in the linux_unopt recipe that will cause the Dart VM to assert if these are used incorrectly. Without these changes, existing tests fail when dart_debug=true in the gn args.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@zanderso
Copy link
Member

zanderso commented Mar 1, 2022

The presubmit test failures appear related to the change.

Copy link
Contributor

@a-siva a-siva left a comment

Choose a reason for hiding this comment

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

How do you ensure that there are no calls to Dart_ThrowException before the calls to Release() ?

@dnfield
Copy link
Contributor Author

dnfield commented Mar 1, 2022

@a-siva - when I build dart with dart_debug = true, assertion failures happen if any allocation happens before the typed data is released. We have existing tests that exercise these code paths, but the assertions were turned off so we never caught them.

I fixed releasing the positions typed data too soon, tests should pass on this commit.

@dnfield
Copy link
Contributor Author

dnfield commented Mar 1, 2022

@dnfield
Copy link
Contributor Author

dnfield commented Mar 2, 2022

tools/gn Outdated

if runtime_mode == 'debug':
gn_args['dart_runtime_mode'] = 'develop'
gn_args['dart_debug'] = args.unoptimized
Copy link
Member

Choose a reason for hiding this comment

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

Could we do this only on linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I removed this. We don't need it here, only on the bot. Localnruns can opt in

for (size_t i = 0; i < uniform_count; i++) {
uniform_floats[i] = uniforms[i];
}
uniforms.Release();
Copy link
Member

Choose a reason for hiding this comment

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

Should we always be doing an explicit Release() on typed data types when they're passed like this? If so, maybe instead of a reference type, they could be passed in such a way that their destructor complains if there wasn't an explicit Release() somewhere?

As it stands with this PR, we're relying on debug unopt unit tests having good coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to do an explicit release before we call any other Dart API. But if we don't call any Dart API, it's fine to not explicitly release the data.

IMHO, the tonic typed data class(es) are poorly designed, mainly because the API they are wrapping is difficult to use correctly. One thing we could try to do is avoid having automatic conversion of these in tonic, since misuse tends to happen where it's unclear that you have to free the passed in argument before you do any other dart_api calls that may allocate anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, put differently: we could refactor the tonic API to not automatically acquire the typed data, and instead just have some way of copying the data to the desired structure since that's what we typically do with this (e.g. SkMatrix, SkData, etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done a couple experiments and filed flutter/flutter#99431. I think it's worth refactoring this further but it should probably be done incrementally and is a bigger task than I can take on at the moment.

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm. In offline discussion it seemed like a good path forward is to fix the existing bug, and file an issue for a better API.

@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 2, 2022
@dnfield
Copy link
Contributor Author

dnfield commented Mar 2, 2022

build_and_test_linux_unopt_debug appears to be a known flake.

@fluttergithubbot fluttergithubbot merged commit e5d43dd into flutter:main Mar 2, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
renyou pushed a commit to renyou/engine that referenced this pull request Mar 3, 2022
renyou added a commit that referenced this pull request Mar 3, 2022
#31786)

* Revert "Reland "Listen for Vsync callback on the UI thread directly""  (#31750)

* Fix invalid usage of typed data detected via dart_debug=true (#31745)

Co-authored-by: Jason Simmons <[email protected]>
Co-authored-by: Dan Field <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs tests waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants