| Summary: | SDL 2.0.7 wrong screen size detection on android | ||
|---|---|---|---|
| Product: | SDL | Reporter: | tibiz <sasha.faryna1234> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | NEW --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | 2.0.7 | ||
| Hardware: | ARM | ||
| OS: | Android (All) | ||
|
Description
tibiz
2017-12-29 23:41:27 UTC
Forgot to tell,but this bug doesn't appear on emulators what is your java method ? maybe this is a change is you targetSdkVersion API ? This is the function to determine the screen size:
private String[] getScreenDimension(){
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getRealMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int dens = dm.densityDpi;
double wi = (double)width / (double)dens;
double hi = (double)height / (double)dens;
double x = Math.pow(wi, 2);
double y = Math.pow(hi, 2);
double screenInches = Math.sqrt(x+y);
String[] screenInformation = new String[3];
screenInformation[0] = String.valueOf(width) + " px";
screenInformation[1] = String.valueOf(height) + " px" ;
screenInformation[2] = String.format("%.2f", screenInches) + " inches" ;
return screenInformation;
}
getScrenDimension()[0] and getScrenDimension()[1] give me the wrong width and height.
This is my API version:
minSdkVersion 19
targetSdkVersion 26
If you build with SDL 2.0.4 and use the same API version as in your 2.0.7, eg minSdkVersion 19 targetSdkVersion 26 what happens ? If I use this:
minSdkVersion 19
targetSdkVersion 26
in SDL 2.0.4 it gives me a correct width and height.Also I have noticed, when logcating with SDL 2.0.7 I get this message "D/SurfaceView: Relayout returned: oldFrame=[0,72][1440,810] newFrame=[0,72][1440,810] result=0x1 surface={Surface(name=null)/@0x87f7d7d isValid=true 542053654016}"
and when using SDL 2.0.4 I get "D/SurfaceView: Relayout returned: oldFrame=[0,72][1920,1080] newFrame=[0,72][1920,1080] result=0x1 surface={Surface(name=null)/@0x87f7d7d isValid=true 542053654016}"
And, why if you use DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); ? If i use this ,I get an error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at org.libsdl.app.SDLActivity.getScreenDimension(SDLActivity.java:170) strange ... you need to call at a good place, not to early maybe. - Also, you can try something in AndroidManifest.xml: android:configChanges="..." see if "screenLayout|fontScale|uiMode|screenSize" matters. - or to comment out the setSystemUiVisibility() in SDLActivity.java - in your logcat, you should also have a line : SDL : Window size: 1080x1920 Otherwise, I don't have much idea ... This is what I get in logcat: SDL : Window size: 1440x810. Anyway,thanks |