-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix the JNI error 'global reference table overflow' caused by receiving a large number of WebSocket messages in the background #17609
Conversation
…ng a large number of WebSocket messages in the background
Interface Check ReportThis pull request does not change any public interfaces ! |
@@ -372,7 +360,7 @@ JNI_PATH(nativeOnStringMessage)(JNIEnv * /*env*/, | |||
jlong handler) { | |||
auto *wsOkHttp3 = HANDLE_TO_WS_OKHTTP3(handler); // NOLINT(performance-no-int-to-ptr) | |||
std::string msgStr = JniHelper::jstring2string(msg); | |||
RUN_IN_GAMETHREAD(wsOkHttp3->onStringMessage(msgStr)); | |||
wsOkHttp3->onStringMessage(msgStr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change it?
The Java side has ensured that nativeOnStringMessage runs on the game thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. But i don't know why need to do synchronization in java instead in c++?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While CocosActivity run on background, the old logic will create jni's global object. And the number of global object may exeed system's limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation also use jni to invoke java codes. Why it doesn't have the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global object is created during the nativeOnBinaryMessage call.
…ng a large number of WebSocket messages in the background (cocos#17609)
…ng a large number of WebSocket messages in the background (cocos#17609) (cherry picked from commit 8f83193)
Re: #
#17552
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: