diff --git a/engine/src/flutter/lib/gpu/device_buffer.cc b/engine/src/flutter/lib/gpu/device_buffer.cc index 7de08bcffc..6d1f845cb5 100644 --- a/engine/src/flutter/lib/gpu/device_buffer.cc +++ b/engine/src/flutter/lib/gpu/device_buffer.cc @@ -74,12 +74,18 @@ bool InternalFlutterGpu_DeviceBuffer_InitializeWithHostData( Dart_Handle wrapper, flutter::gpu::Context* gpu_context, Dart_Handle byte_data) { - auto data = tonic::DartByteData(byte_data); - auto mapping = fml::NonOwnedMapping(reinterpret_cast(data.data()), - data.length_in_bytes()); - auto device_buffer = - gpu_context->GetContext()->GetResourceAllocator()->CreateBufferWithCopy( - mapping); + std::shared_ptr device_buffer = nullptr; + { + // `DartByteData` gets raw pointers into the Dart heap via + // `Dart_TypedDataAcquireData`. So it must be destructed before + // `AssociateWithDartWrapper` is called, which mutates the heap. + auto data = tonic::DartByteData(byte_data); + auto mapping = fml::NonOwnedMapping(reinterpret_cast(data.data()), + data.length_in_bytes()); + device_buffer = + gpu_context->GetContext()->GetResourceAllocator()->CreateBufferWithCopy( + mapping); + } if (!device_buffer) { FML_LOG(ERROR) << "Failed to create device buffer with copy."; return false; diff --git a/engine/src/flutter/testing/dart/gpu_test.dart b/engine/src/flutter/testing/dart/gpu_test.dart index 267d3f0f06..8c296d5324 100644 --- a/engine/src/flutter/testing/dart/gpu_test.dart +++ b/engine/src/flutter/testing/dart/gpu_test.dart @@ -7,7 +7,6 @@ // ignore_for_file: avoid_relative_lib_imports -import 'dart:io'; import 'dart:typed_data'; import 'dart:ui' as ui; @@ -398,13 +397,6 @@ void main() async { // Regression test for https://github.com/flutter/flutter/issues/157324 test('Can bind uniforms in range', () async { - // TODO(bdero): createDeviceBufferWithCopy triggers an assert in - // third_party/dart on Linux. - // https://github.com/flutter/flutter/issues/157336 - if (Platform.isLinux) { - return; - } - final state = createSimpleRenderPass(); final gpu.RenderPipeline pipeline = createUnlitRenderPipeline();