ANDROID: Avoid use-after-free when setting up touch mode

We set up touch mode in graphics managers constructor.
At this point, the _graphicsManager variable was pointed to the freshly
deleted old manager instead of being null.
When we are in this position, assume the cursor is at top left.
This commit is contained in:
Le Philousophe 2024-06-22 19:25:39 +02:00
parent fe5fddd37e
commit 3a57523490
2 changed files with 8 additions and 1 deletions

View File

@ -970,6 +970,7 @@ bool OSystem_Android::setGraphicsMode(int mode, uint flags) {
if (render3d && !supports3D) {
debug(5, "switching to 3D graphics");
delete _graphicsManager;
_graphicsManager = nullptr;
AndroidGraphics3dManager *manager = new AndroidGraphics3dManager();
_graphicsManager = manager;
androidGraphicsManager = manager;
@ -977,6 +978,7 @@ bool OSystem_Android::setGraphicsMode(int mode, uint flags) {
} else if (!render3d && supports3D) {
debug(5, "switching to 2D graphics");
delete _graphicsManager;
_graphicsManager = nullptr;
AndroidGraphicsManager *manager = new AndroidGraphicsManager();
_graphicsManager = manager;
androidGraphicsManager = manager;

View File

@ -1541,7 +1541,12 @@ void OSystem_Android::setupTouchMode(int oldValue, int newValue) {
if (newValue == TOUCH_MODE_TOUCHPAD) {
// Make sure we have a proper touch point if we switch to touchpad mode with finger down
_touch_pt_down = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
if (_graphicsManager) {
_touch_pt_down = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
} else {
_touch_pt_down.x = 0;
_touch_pt_down.y = 0;
}
_touch_pt_scroll.x = -1;
_touch_pt_scroll.y = -1;
}