Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #17594: [android] fix crash and memory leaks if launching game multiple times on Android platform with PhysX module enabled. #17602

Merged
merged 9 commits into from
Sep 4, 2024

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Sep 4, 2024

Re: #17594

cocos/google-game-sdk#9
cocos/cocos-engine-external#458

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Greptile Summary

This pull request updates the external dependency version for the engine-native-external repository, addressing crash and memory leak issues on Android platforms with PhysX module enabled.

  • Updated native/external-config.json to use engine-native-external version v3.8.5-1, up from v3.8.4-5
  • This change likely incorporates fixes for the ADPFManager class, including proper resource cleanup and improved header inclusion

@dumganhar dumganhar changed the base branch from v3.8.4 to v3.8.5 September 4, 2024 07:11
Copy link

github-actions bot commented Sep 4, 2024

Interface Check Report

This pull request does not change any public interfaces !

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings

Comment on lines +89 to +91
// Move the map to avoid erase operation in the following for loop since 'delete' will trigger ~PhysxSharedBody.
// clearCache is invoked only in the destructor of PhysXWorld.
auto tmpMap = std::move(sharedBodesMap);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a unique_ptr for automatic memory management of PhysXSharedBody instances

@@ -87,6 +87,12 @@ void ADPFManager::initialize() {
}
}

void ADPFManager::destroy() {
JNIEnv *env = cc::JniHelper::getEnv();
env->DeleteGlobalRef(obj_power_service_);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider checking if obj_power_service_ is not null before deleting

Comment on lines 55 to 60
public static void destroy() {
mDatabaseOpenHelper = null;
if (mDatabase != null) {
mDatabase.close();
mDatabase = null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a null check before closing mDatabase to prevent potential NullPointerException

Comment on lines +61 to +64
public static void resetStaticVariables() {
mSensorHandler = null;
mEnableSensor = false;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding synchronization to prevent potential race conditions when resetting static variables.

Comment on lines +62 to +65
if (mVideoHandler != null) {
mVideoHandler.removeCallbacksAndMessages(null);
mVideoHandler = null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more specific method like removeCallbacks() instead of removeCallbacksAndMessages(null) if possible

Comment on lines +62 to +63
sHandler.removeCallbacksAndMessages(null);
sHandler = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure all callbacks are removed before setting sHandler to null to prevent potential memory leaks

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@dumganhar dumganhar changed the title fixed #17594: fix crash if launching game multiple times on Android platform with PhysX module enabled. fixed #17594: fix crash and memory leaks if launching game multiple times on Android platform with PhysX module enabled. Sep 4, 2024
@dumganhar dumganhar changed the title fixed #17594: fix crash and memory leaks if launching game multiple times on Android platform with PhysX module enabled. fixed #17594: [android] fix crash and memory leaks if launching game multiple times on Android platform with PhysX module enabled. Sep 4, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

18 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Comment on lines +89 to +91
// Move the map to avoid erase operation in the following for loop since 'delete' will trigger ~PhysxSharedBody.
// clearCache is invoked only in the destructor of PhysXWorld.
auto tmpMap = std::move(sharedBodesMap);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a unique_ptr for automatic memory management of PhysXSharedBody instances

@@ -87,6 +87,12 @@ void ADPFManager::initialize() {
}
}

void ADPFManager::destroy() {
JNIEnv *env = cc::JniHelper::getEnv();
env->DeleteGlobalRef(obj_power_service_);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider checking if obj_power_service_ is not null before deleting

@@ -53,8 +53,10 @@ public static boolean init(String dbName, String tableName) {
}

public static void destroy() {
mDatabaseOpenHelper = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a null check before setting mDatabaseOpenHelper to null

Comment on lines +62 to +65
if (mVideoHandler != null) {
mVideoHandler.removeCallbacksAndMessages(null);
mVideoHandler = null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more specific method like removeCallbacks() instead of removeCallbacksAndMessages(null) if possible

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@dumganhar dumganhar merged commit 55c81c3 into cocos:v3.8.5 Sep 4, 2024
24 checks passed
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

github-actions bot commented Sep 5, 2024

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL Hexa,puzzle,shield-node
ios PASS PASS FAIL Hexa,puzzle,shield-node
mac PASS PASS FAIL Hexa,puzzle,shield-node

Copy link

github-actions bot commented Sep 5, 2024

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS FAIL Hexa,puzzle,shield-node
android PASS PASS FAIL Hexa,puzzle,shield-node
wechatgame PASS FAIL FAIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants