-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
Android getSafeAreaRect() Wrong values #2175
Comments
I recall making the change to support the rounded corners, and added the call: The I didn't notice any issues at the time, but have you by any chance stepped through the code to see why the values are different? Is it happening on specific devices? |
I tried on 2 devices and same behavior. For It's your I noticed that the As side note, I hope there isn't many calls to the JNI stored in static var with pointer in Axmol, because this could cause much troubles |
I'll check that out later today.
The only reason I can think of for the use of the statics is to avoid JNI calls for data that should not be changing is most likely because they're expensive to make. The pointer is pointing to an address that should not change (from my understanding), because of the use of the |
Yeah for sure it’s to save JNI calls; I also thought that at first and tried to store as static member in AxmolEngine the int[] but no changes, but what was strange is that I got 0 after even if it could be from anywhere in the memory. Then I looked at JniHelper::callStaticIntArrayMethod and understood: axmol/core/platform/android/jni/JniHelper.h Line 271 in f320ba1
The function declares a static int ret[32] and then memcopy the result got from java into this array… But any code calling this method will use the same ret array in memory as it’s static…. and the last call will override the previous result… and what is the other call right after? The safeInsets ones, that returns 0. That explains why I have always 0 after. I also wonder why it’s hard coded 32 as maximum array length. We can’t remove the static keyword for |
I had absolutely no idea that this was the case, given that the method is generic. Checking back how long it's been in there, again from Cocos2d-x:
That is exactly the reason. Thanks for looking into the issue. A few possible ways to fix this come to mind:
No matter what, the code calling Any other ideas on how this should be implemented? EDIT: The safe area and corner radii are affected by the layout mode set by the application. Would the layout mode ever change at runtime (check display-cutout and rounded-corners)? If they can change, then caching the values is pointless, and we would have to make the JNI calls on every request for the values. |
Possible solution:
then in
and Instead of checking for a This way the caller is responsible for caching the values, as it is not the responsibility of the JNI helper methods to be caching values. |
@AlexandreK38 Check #2178 please. This is all assuming that the values of the safe area should never change for the duration of the application, and that the app layout is only set once on start-up. The functionality hasn't changed from how it is right now, except the bug is fixed. |
@rh101 I never saw
The cut out is changed in the AppActivity in the |
Steps to Reproduce:
The cause comes from the static var below, the first time the JNI is called and values computed and stored in the static array, but the next call the JNI is not called and the values are 0.
It seems to an issue with static variable in java.
The fix is just to remove the static keyword.
The text was updated successfully, but these errors were encountered: