Closed SamuelBrucksch closed 3 weeks ago
Got some more logs, that might help to identify if this is on mapbox side:
05-30 21:10:07.265 1000 1228 1331 D PowerManagerService: displayReady: false groupId=0
05-30 21:10:07.265 1000 1228 1331 D DisplayPowerController[0]: animateScreenStateChange: target=2, mLogicalDisplay.isEnabled()=true
05-30 21:10:07.265 1000 1228 1331 D DisplayPowerController[0]: getFinalBrightness : Summary is 70 (0.27) -> 70 (0.27)
05-30 21:10:07.265 1000 1228 1331 D PowerManagerService: displayReady: true groupId=0
05-30 21:10:07.267 10229 11935 23371 E BufferQueueProducer: [SurfaceView - cqr@331c41f@0#10(BLAST Consumer)10](id:2e9f0000000a,api:1,p:16588,c:11935) connect: BufferQueue has been abandoned
05-30 21:10:07.267 10431 16588 22565 E vulkan : native_window_api_connect() failed: No such device (-19)
05-30 21:10:07.268 10431 16588 22565 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
05-30 21:10:07.268 10431 16588 22565 E Mbgl-EglCore: eglCreateWindowSurface: EGL error: 0x300d
05-30 21:10:07.269 10229 11935 22758 E BufferQueueProducer: [SurfaceView - cqr@331c41f@0#10(BLAST Consumer)10](id:2e9f0000000a,api:1,p:16588,c:11935) connect: BufferQueue has been abandoned
05-30 21:10:07.269 10431 16588 22565 E vulkan : native_window_api_connect() failed: No such device (-19)
05-30 21:10:07.269 10431 16588 22565 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
05-30 21:10:07.269 10431 16588 22565 E Mbgl-EglCore: eglCreateWindowSurface: EGL error: 0x300d
05-30 21:10:07.269 10229 11935 22758 E BufferQueueProducer: [SurfaceView - cqr@331c41f@0#10(BLAST Consumer)10](id:2e9f0000000a,api:1,p:16588,c:11935) connect: BufferQueue has been abandoned
05-30 21:10:07.270 10431 16588 22565 E vulkan : native_window_api_connect() failed: No such device (-19)
05-30 21:10:07.270 10431 16588 22565 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
05-30 21:10:07.270 10431 16588 22565 E Mbgl-EglCore: eglCreateWindowSurface: EGL error: 0x300d
05-30 21:10:07.270 10229 11935 22758 E BufferQueueProducer: [SurfaceView - cqr@331c41f@0#10(BLAST Consumer)10](id:2e9f0000000a,api:1,p:16588,c:11935) connect: BufferQueue has been abandoned
05-30 21:10:07.270 10431 16588 22565 E vulkan : native_window_api_connect() failed: No such device (-19)
05-30 21:10:07.271 10431 16588 22565 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
05-30 21:10:07.271 10431 16588 22565 E Mbgl-EglCore: eglCreateWindowSurface: EGL error: 0x300d
@SamuelBrucksch Are you using https://github.com/mapbox/mapbox-maps-android/releases/tag/extension-androidauto-v0.1.0? The framework is responsible for ensuring these issues do not happen.
If you are attempting to build your own wrapper around the maps sdk, it will need to be maintained separately - so please try to use the extension-androidauto
To help with the issue though, this is the code inside the SDK that is responsible for ensuring the map surface is destroyed https://github.com/mapbox/mapbox-maps-android/blob/6b0b4a0925f4655bab7c4bdc443a33343d65c881/extension-androidauto/src/main/java/com/mapbox/maps/extension/androidauto/CarMapSurfaceOwner.kt#L68-L70
Hi,
Thanks for the reply, no we do not use the android auto extension (yet). But as you can see in the code above, we do exactly the same as you referenced in that lib. It also does not happen for many people, but seems to be specific to some rare cases.
So this error happens, if the map surface is not destroyed correctly and when another surface created event comes in we try to create another MapSurface although the previous one is not correctly destroyed yet?
We call destroy in on stop and onSurfaceDestroyed, from my understanding this should be good enough...
I can reproduce this behaviour, when our app is running on AA and currently active on the screen. If I then install a new version of our app, while the current app is still running, I see this libEGL error.
I also tried it with the sample app, and i can reproduce the same behavior. Just install it, start it and while it is active on the Android Auto screen install it again and you should see lot's of these libEGL errors.
Not sure if this is a valid test and is the same situation as the user has, but it is the only way to reproduce this for me now...
If you then click on the search button and go back, the map updates again. So it actually can clean up on destroy and come back on a new surface... However it doesn't do that in this case after an install and it might be the same reason why it doesn't work for the above mentioned user.
I also tried it with the sample app, and i can reproduce the same behaviour. Just install it, start it and while it is active on the Android Auto screen install it again and you should see lot's of these libEGL errors.
Ok I can reproduce with this as well.
2022-06-06 14:04:52.885 15926-15926/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceCallback]: onSurfaceAvailable [Surface(name=null)/@0x751b2d2, 800x400, dpi: 160]
2022-06-06 14:04:53.019 15926-15926/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceCallback]: onVisibleAreaChanged visibleArea:Rect(0, 112 - 716, 400)
2022-06-06 14:04:59.038 16390-16390/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceCallback]: onSurfaceAvailable [Surface(name=null)/@0xd737d66, 800x400, dpi: 160]
2022-06-06 14:04:59.208 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0xb40000753a1a12b0) failed (0xffffffea) (already connected to another API?)
2022-06-06 14:04:59.208 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurfaceTmpl:676 error 3003 (EGL_BAD_ALLOC)
2022-06-06 14:04:59.208 16390-16420/com.mapbox.maps.testapp.auto E/Mapbox: [maps-android\Mbgl-EglCore]: eglCreateWindowSurface: EGL error: 0x3003
2022-06-06 14:04:59.256 16390-16390/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceCallback]: onVisibleAreaChanged visibleArea:Rect(0, 112 - 716, 400)
2022-06-06 14:04:59.259 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0xb40000753a1a12b0) failed (0xffffffea) (already connected to another API?)
2022-06-06 14:04:59.259 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurfaceTmpl:676 error 3003 (EGL_BAD_ALLOC)
2022-06-06 14:04:59.259 16390-16420/com.mapbox.maps.testapp.auto E/Mapbox: [maps-android\Mbgl-EglCore]: eglCreateWindowSurface: EGL error: 0x3003
2022-06-06 14:04:59.311 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0xb40000753a1a12b0) failed (0xffffffea) (already connected to another API?)
2022-06-06 14:04:59.311 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurfaceTmpl:676 error 3003 (EGL_BAD_ALLOC)
2022-06-06 14:04:59.311 16390-16420/com.mapbox.maps.testapp.auto E/Mapbox: [maps-android\Mbgl-EglCore]: eglCreateWindowSurface: EGL error: 0x3003
2022-06-06 14:04:59.362 16390-16420/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0xb40000753a1a12b0) failed
onSurfaceDestroyed
is never called when there is a reload with the desktop_head_unit
. That is not actually a production use case, unless the android auto system creates this same behavior when attach/detaching the head unit. In that case, it's an issue to send to https://issuetracker.google.com/u/0/issues?q=componentid:460472
EDIT: recovery is restarting the desktop_head_unit
And in the lifecycle code we do this:
@Override public void onDestroy(@NonNull LifecycleOwner owner) { if (mapSurface != null) { mapSurface.onStop(); mapSurface.surfaceDestroyed(); mapSurface.onDestroy(); } }
I don't think this is needed. The surface destroy call is called before a car session is destroyed. It's not fixing the libEGL error, but it is not making it worse either.
Ok so I will add some logging for that user if onSurfaceDestroyed and onSurfaceCreated is called correctly, and if not, I will open an issue at Google and if both are correctly called I will report back here.
https://issuetracker.google.com/u/0/issues/235121269
@SamuelBrucksch I just made an issue for this :)
Great, thanks. Will add my findings to that issue then if there are any...
But, maybe something else we can do in this extension. Is when a surface is created, and a new one is being created. Delete the old one
EDIT: This doesn't help because the old surface is in memory and it is cleared when the app is re-installed. Notice AndroidAutoApplication.onCreate is called, so we can't delete the old surface
2022-06-06 14:30:41.013 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\AndroidAutoApplication]: onCreate
2022-06-06 14:30:41.071 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 1
2022-06-06 14:30:41.072 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 2
2022-06-06 14:30:41.074 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 3
2022-06-06 14:30:41.334 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: surfaceAvailable
2022-06-06 14:30:41.420 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: surfaceVisibleAreaChanged
2022-06-06 14:30:41.421 23536-23536/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: notifyVisibleAreaChanged Rect(0, 112 - 716, 400) [top: 112.0, left: 0.0, bottom: 0.0, right: 84.0]
2022-06-06 14:30:48.563 23680-23680/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\AndroidAutoApplication]: onCreate
2022-06-06 14:30:48.605 23680-23680/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 1
2022-06-06 14:30:48.606 23680-23680/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 2
2022-06-06 14:30:48.609 23680-23680/com.mapbox.maps.testapp.auto I/Mapbox: [maps-android\CarMapSurfaceOwner]: registerObserver + 1 = 3
2022-06-06 14:30:48.780 23680-23712/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurface: native_window_api_connect (win=0xb40000753a19ce90) failed (0xffffffea) (already connected to another API?)
2022-06-06 14:30:48.780 23680-23712/com.mapbox.maps.testapp.auto E/libEGL: eglCreateWindowSurfaceTmpl:676 error 3003 (EGL_BAD_ALLOC)
2022-06-06 14:30:48.781 23680-23712/com.mapbox.maps.testapp.auto E/Mapbox: [maps-android\Mbgl-EglCore]: eglCreateWindowSurface: EGL error: 0x3003
Is this possible from our app too? Then I could add that as well and check if it works for that user. This shouldn't work for the re-installation though, as it is a seperate instance.... Do you have a code snipped i could try? In the case with the user it should still be the same instance theoretically.
I just tried it and it doesn't help. the android auto car library would need to tell us to destroy the surface. The surface continues to exist in the desktop head unit, and any downstream application will have no way to clean up an old surface
https://github.com/mapbox/mapbox-maps-android/issues/1397#issuecomment-1147944018
if that happens on production, that would definitely be a memory leak that the google car team would want to fix.
Ok then I'll verify that with more logging. Thanks for your support so far.
Got the logs and it actually looks like "onSurfaceAvailable" is called two times right after another:
06-07 11:32:19.838 10438 7917 7917 D MapRenderer: onPause
06-07 11:32:19.867 10438 7917 7917 D MapRenderer: onStop
06-07 11:32:19.868 10438 7917 7917 D MapRenderer: onSurfaceDestroyed
06-07 11:32:19.868 10438 7917 7917 D MapRenderer: clearing mapbox map listeners
06-07 11:32:19.873 10438 7917 7917 D MapRenderer: mapSurface.onStop()
06-07 11:32:19.880 10438 7917 7917 D MapRenderer: mapSurface.surfaceDestroyed()
06-07 11:32:19.909 10438 7917 7917 D MapRenderer: mapSurface.onDestroy()
06-07 11:32:37.381 10438 7917 7917 D MapRenderer: onStart
06-07 11:32:37.430 10438 7917 7917 D MapRenderer: onResume
06-07 11:32:37.461 10438 7917 7917 D MapRenderer: onSurfaceAvailable: surface is not null
06-07 11:32:37.576 10438 7917 7917 D MapRenderer: Cache size: 128
06-07 11:32:37.637 10438 7917 7917 D MapRenderer: onSurfaceAvailable: surface is not null
06-07 11:32:37.701 10438 7917 24593 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
06-07 11:32:37.701 10438 7917 7917 D MapRenderer: Cache size: 128
06-07 11:32:37.704 10438 7917 24593 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
06-07 11:32:37.704 10438 7917 24593 D libEGL : ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:32.
Then a possible solution might be to check if a mapsurface already exists and if so destroy it and create a new one... However that is actually just a workaround rather than a solution. Will let google know about this log.
I'll check if the workaround works with the user and let you know.
New Google Issue: https://issuetracker.google.com/u/0/issues/235172947
So on a first quick test the user said it worked, did not get another report yet for a longer test where he did more switching between the app.
My workaround looks like this:
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
synchronized (MapRenderer.this) {
...
if (mapSurface != null) {
// if this is called twice shut down previous mapbox instance
shutdownMapbox();
}
... // mapbox initialization
}
}
private void shutdownMapbox() {
if (mapboxMap != null) {
mapboxMap.removeOnCameraChangeListener(MapRenderer.this::onCameraChanged);
mapboxMap.removeOnStyleImageMissingListener(MapRenderer.this::onStyleImageMissing);
mapboxMap.removeOnStyleLoadedListener(MapRenderer.this::onStyleLoaded);
mapboxMap.removeOnRenderFrameFinishedListener(MapRenderer.this::onRegionChange);
}
if (mapSurface != null) {
mapSurface.onStop();
mapSurface.surfaceDestroyed();
mapSurface.onDestroy();
}
mapboxMap = null;
mapSurface = null;
}
My proposal here would also be to offer a function, to update the surface of the MapSurface, if that is possible. Like mapSurface.surfaceChanged(surface)
Because then we could initialize the MapSurface only once, and just update the Surface every time onSurfaceAvailable is called. Not sure if that makes sense fom mapbox perspective, but would avoid to reinitilize mapbox all the time. @kmadsen what do you think?
My proposal here would also be to offer a function, to update the surface of the MapSurface, if that is possible. Like mapSurface.surfaceChanged(surface) Because then we could initialize the MapSurface only once, and just update the Surface every time onSurfaceAvailable is called. Not sure if that makes sense fom mapbox perspective, but would avoid to reinitilize mapbox all the time. @kmadsen what do you think?
Considering this surfaceChanged function, the purpose of it would be to simplify the interactions with the mapSurface? There is a solution available for simplifying map interactions with android auto in the extension https://github.com/mapbox/mapbox-maps-android/issues/1397#issuecomment-1147778664. It is designed to work well with surface recreation because android auto will recreate the surface when you open the search screen and back to the map.
Can you use the MapboxCarMap to help with the surface interactions?
The MapSurface definition is under an api contract, so the changes to that API requires a lot of justification. Notice how the surface is passed to the constructor. Changing it would require a migration from downstream developers. Maybe still worth exploring, but I'm more interested in the reason why you don't want to use MapboxCarMap
cc: @SamuelBrucksch also sorry for the delay, am catching up on messages after a summer vacation
Stale, outdated.
Hi,
we have an android app that uses mapbox for android auto. Sometimes we see an error like this:
This error repeats every few miliseconds and spams the log a lot so we can not really see the error that ocurred.
I'm not really sure if it is related to mapbox, but i haven't seen it before, when we still used osmdroid. However it could as well be related to Android Auto, but the behaviour we see is that android auto behaves normally, even updates all the UIs like distance and instructions on the car display, but the map is frozen.
For some people it happens when switching to other apps and back, so maybe related to the lifecycle. I also saw it a few times during development and thought it migth have been an issue with the emulator, when installing a new testversion and the old version was still running.
We currently use
And our code for SurfaceCallback is this:
And in the lifecycle code we do this:
Do you have any idea, what could cause the above error? It almost seams as if that error comes for each time the map tries to render, it is logged every few ms.
As for some people it happens when switching between apps in android auto, i could imagine that somethin in the lifecycle causes the surface not being cleaned up correctly or so. Any hints on that?