use weakptr to avoid use flutter ace view after delete

Signed-off-by: zcdqs <junfeng.lijunfeng@huawei.com>
Change-Id: Ia498319692a528cefc4420bd3c9d99eeb83ec74a
This commit is contained in:
zcdqs
2022-04-20 08:57:15 +08:00
parent f3fd15480e
commit fd3ccfdcf4
2 changed files with 10 additions and 3 deletions
+5 -2
View File
@@ -21,6 +21,7 @@
#include "adapter/ohos/entrance/ace_application_info.h"
#include "adapter/ohos/entrance/data_ability_helper_standard.h"
#include "adapter/ohos/entrance/file_asset_provider.h"
#include "adapter/ohos/entrance/flutter_ace_view.h"
#include "base/log/ace_trace.h"
#include "base/log/event_report.h"
#include "base/log/frame_report.h"
@@ -160,8 +161,10 @@ void AceContainer::DestroyView()
{
ContainerScope scope(instanceId_);
if (aceView_ != nullptr) {
delete aceView_;
aceView_ = nullptr;
auto flutterAceView = static_cast<FlutterAceView*>(aceView_);
if (flutterAceView) {
flutterAceView->DecRefCount();
}
}
}
+5 -1
View File
@@ -307,6 +307,9 @@ void LogPointInfo(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEventRunner, bool usePlatformThread)
{
FlutterAceView* aceSurface = new Platform::FlutterAceView(instanceId);
if (aceSurface != nullptr) {
aceSurface->IncRefCount();
}
flutter::Settings settings;
settings.instanceId = instanceId;
settings.platform = flutter::AcePlatform::ACE_PLATFORM_OHOS;
@@ -319,7 +322,8 @@ FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEv
settings.use_current_event_runner = useCurrentEventRunner;
LOGI("software render: %{public}s", settings.enable_software_rendering ? "true" : "false");
LOGI("use platform as ui thread: %{public}s", settings.platform_as_ui_thread ? "true" : "false");
settings.idle_notification_callback = [aceSurface](int64_t deadline) {
settings.idle_notification_callback = [weak = WeakClaim(aceSurface)](int64_t deadline) {
auto aceSurface = weak.Upgrade();
if (aceSurface != nullptr) {
aceSurface->ProcessIdleEvent(deadline);
}