Skip to content

Commit

Permalink
fix(perf): fix OnResourceLoadEnd crash (#3888)
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao authored Jun 11, 2024
1 parent 2d9837b commit 948927c
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ std::shared_ptr<Scope> GetScope(jint j_scope_id) {

void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong startTime, jlong endTime) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, startTime, endTime]() {
Expand All @@ -187,7 +191,11 @@ void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong sta

void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, time]() {
Expand All @@ -211,7 +219,11 @@ void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong tim

void OnFirstContentfulPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, time]() {
Expand All @@ -235,7 +247,11 @@ void OnResourceLoadEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jstring
auto ret_code = static_cast<int32_t>(j_ret_code);
auto error_msg = j_error_msg ? JniUtils::ToStrView(j_env, j_error_msg) : string_view("");
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
auto engine = scope->GetEngine().lock();
if (!engine) {
return;
}
auto runner = engine->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, uri, j_start_time, j_end_time, ret_code, error_msg]() {
Expand Down

0 comments on commit 948927c

Please sign in to comment.