Skip to content

Commit 587a346

Browse files
committed
shell/gpu: call Context virtuals instead of downcasting to ContextVK
impeller_context_ is a shared_ptr<impeller::Context> handed in by the caller, and it is often a SurfaceContextVK, which derives from Context rather than ContextVK. ContextVK::Cast on it is an unchecked downcast: DisposeThreadLocalCachedResources then locks desc_pool_mutex_ at the wrong offset, pthread_mutex_lock returns EINVAL, and the process aborts. The same member is cast to SurfaceContextVK a few lines below, so the two casts could not both be right. DisposeThreadLocalCachedResources, CreateCommandBuffer and GetCommandQueue are all virtual on Context and SurfaceContextVK overrides or delegates them, so call through the base and drop the casts.
1 parent 4ec652a commit 587a346

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

‎engine/src/flutter/shell/gpu/gpu_surface_vulkan_impeller.cc‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
9494
// Skipping it when the compositor presents would leave the raster thread
9595
// holding those pools for the life of the engine.
9696
if (impeller_context_) {
97-
impeller::ContextVK::Cast(*impeller_context_)
98-
.DisposeThreadLocalCachedResources();
97+
impeller_context_->DisposeThreadLocalCachedResources();
9998
}
10099

101100
// Nothing to acquire or present when an external view embedder owns
@@ -260,12 +259,10 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
260259
TRACE_EVENT0("flutter", "GPUSurfaceVulkan::PresentImage");
261260

262261
{
263-
const auto& context = impeller::ContextVK::Cast(*impeller_context);
264-
265262
//----------------------------------------------------------------------------
266263
/// Transition the image to color-attachment-optimal.
267264
///
268-
auto cmd_buffer = context.CreateCommandBuffer();
265+
auto cmd_buffer = impeller_context->CreateCommandBuffer();
269266

270267
auto vk_final_cmd_buffer =
271268
impeller::CommandBufferVK::Cast(*cmd_buffer).GetCommandBuffer();
@@ -286,7 +283,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
286283
return false;
287284
}
288285
}
289-
if (!context.GetCommandQueue()->Submit({cmd_buffer}).ok()) {
286+
if (!impeller_context->GetCommandQueue()->Submit({cmd_buffer}).ok()) {
290287
return false;
291288
}
292289
}

0 commit comments

Comments
 (0)