mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 15:00:12 +00:00
!10607 js scene post task may crash because of freed scheduler
Merge pull request !10607 from janjan/js_utils_crash
This commit is contained in:
commit
c53305bc31
@ -1518,6 +1518,7 @@ MainThreadScheduler::MainThreadScheduler(napi_env env)
|
||||
: env_(env)
|
||||
{
|
||||
GetMainEventHandler();
|
||||
envChecker_ = std::make_shared<int>(0);
|
||||
}
|
||||
|
||||
inline void MainThreadScheduler::GetMainEventHandler()
|
||||
@ -1535,8 +1536,12 @@ inline void MainThreadScheduler::GetMainEventHandler()
|
||||
void MainThreadScheduler::PostMainThreadTask(Task&& localTask, std::string traceInfo, int64_t delayTime)
|
||||
{
|
||||
GetMainEventHandler();
|
||||
auto task = [env = env_, localTask, traceInfo] () {
|
||||
auto task = [env = env_, localTask, traceInfo, envChecker = std::weak_ptr<int>(envChecker_)]() {
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "SCBCb:%s", traceInfo.c_str());
|
||||
if (envChecker.expired()) {
|
||||
TLOGNE(WmsLogTag::WMS_MAIN, "post task expired because of invalid scheduler");
|
||||
return;
|
||||
}
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env, &scope);
|
||||
localTask();
|
||||
|
@ -202,6 +202,7 @@ public:
|
||||
private:
|
||||
void GetMainEventHandler();
|
||||
napi_env env_;
|
||||
std::shared_ptr<int> envChecker_;
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
Loading…
Reference in New Issue
Block a user