| Summary: | Accelerometer name returns constant value | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Joseba García Echebarria <joseba.gar> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | CC: | philipp.wiesemann |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: | Update accelerometer name. | ||
This implementation sets the name again for every change from sensor. Maybe it could only be set once and then only changed if the name is different (what should happen very often :). Else there will be a lot of not needed string allocations.
Also the last string allocated with strndup() is always leaked when the name is set again.
In the old implementation the value of accelerometerName was always a pointer to a string ("Android accelerometer") but in this implementation it has an undefined value until a change from sensor. It may be used before which may be unwanted.
Maybe SDL_strdup() could be used instead of strndup() because the whole string will be copied anyway. Using strlen() does work which is not needed then.
Is it typical for there to be more than one accelerometer in an Android device? What does the name typically look like? Is it expensive to pass a Java string across the JNI interface? Yesterday I finished a working joystick implementation for Android. It's based on an older version of SDL2 HG. That code sets the accelerometer (and joystick) names when the joystick subsystem is initialized and avoids the leaks mentioned by freeing everything when the subsystem is closed. I'll adapt the code for the latest version of SDL and will submit it to bugzilla for consideration so I'm closing this bug report. Regards (In reply to comment #2) > Is it typical for there to be more than one accelerometer in an Android device? > What does the name typically look like? Is it expensive to pass a Java string > across the JNI interface? |
Created attachment 998 [details] Update accelerometer name. In Android the accelerometer name is always returned as "Android accelerometer". The attached patch will update the accelerometer name with the one given by Android for the sensor that called the onNativeAccel function.