Open firdiar-mita opened 1 month ago
Hi, thank you for reporting bug and suggestion. As you say, I have to release not only native texture but also Unity's texture 2D. I have included your suggestion in latest update. Thank you very much.
ps: Maybe my latest update not seems apropriate. I need to release shared texture on rendering thread
Thanks for the update!
@TLabAltoh using latest version, i got freeze, when destroying webview but I didn't investigate further about the cause
Note: I did update the VKeyboard
Thanks for the info. In the latest update, I also updated the native plugin to change the process of release native resources. If you have not merged the diff of the native plugin, please check it. Or is it already checked?
(Please forget above. I just assumed that you manually merged the change from this repo. But I leave above just to be sure).
Additinaly, if you could, please let me know your project settings. I want to know graphics api (OpenGLES or Vulkan?) and multithreaded rendering option and unity version.
Below is the small update of my java plugin.
/**
* I need to call this function on unity's render thread because
* releaseSharedTexture() call GLES or Vulkan function and it
* needs to be called on render thread.
*/
public void Destroy() {
releaseSharedTexture(); // I have moved the release texture resource process to here.
final Activity a = UnityPlayer.currentActivity;
a.runOnUiThread(() -> {
if (mWebView == null) {
return;
}
mWebView.stopLoading();
mGlLayout.removeView(mWebView);
mWebView.destroy();
mWebView = null;
UnityPlayer.currentActivity.unregisterReceiver(
mOnDownloadComplete);
});
}
I will merge other issues recommendations later...
@TLabAltoh hello sorry for my late reply i update the package by delete everything and add the new one
related to freeze, this is the logs
2024/07/22 14:43:24.673 20086 20233 Error Unity UnityException: Destroy can only be called from the main thread.
2024/07/22 14:43:24.673 20086 20233 Error Unity Constructors and field initializers will be executed from the loading thread when loading a scene.
2024/07/22 14:43:24.673 20086 20233 Error Unity Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
2024/07/22 14:43:24.673 20086 20233 Error Unity at (wrapper managed-to-native) UnityEngine.Object.Destroy(UnityEngine.Object,single)
2024/07/22 14:43:24.673 20086 20233 Error Unity at UnityEngine.Object.Destroy (UnityEngine.Object obj) [0x00007] in /home/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:423
2024/07/22 14:43:24.673 20086 20233 Error Unity at TLab.Android.WebView.TLabWebView.DestroyNativePlugin (System.Int32 id) [0x00061] in D:\Work\XXXX\Assets\Plugins\TLabWebView-master\Runtime\TLabWebView.cs:146
2024/07/22 14:43:24.673 20086 20233 Error Unity at (wrapper native-to-managed) TLab.Android.WebView.TLabWebView.DestroyNativePlugin(int)
2024/07/22 14:43:24.673 20086 20233 Error Unity UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
2024/07/22 14:43:24.673 20086 20233 Error Unity UnityEngine.DebugLogHandler:LogException(Exception, Object)
2024/07/22 14:43:24.673 20086 20233 Error Unity UnityEngine.Logger:LogException(Exception, Object)
2024/07/22 14:43:24.673 20086 20233 Error Unity UnityEngine.Debug:LogEx
i think unity texture can only being removed in unity mainthread
although i fixed the destroy problem, the leaking problem are back
i think this worser? i just start 2 webview, unload the scene, and load again, then it's crashing
2024/07/22 15:04:46.710 23786 24023 Error Unity Could not allocate memory: System out of memory!
2024/07/22 15:04:46.710 23786 24023 Error Unity Trying to allocate: 16767092B with 16 alignment. MemoryLabel: Serialization
2024/07/22 15:04:46.710 23786 24023 Error Unity Allocation happened at: Line:72 in ./Runtime/Core/Containers/Vector.h
2024/07/22 15:04:46.710 23786 24023 Error Unity Memory overview
2024/07/22 15:04:46.710 23786 24023 Error Unity
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TEMP_TLS ] used: 141248B | peak: 0B | reserved: 6881280B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_MEMORYPROFILER ] used: 2441316B | peak: 2449408B | reserved: 3145728B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_DEFAULT ] used: 156483420B | peak: 0B | reserved: 184578048B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TEMP_JOB_1_FRAME ] used: 0B | peak: 0B | reserved: 0B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TEMP_JOB_2_FRAMES ] used: 0B | peak: 0B | reserved: 0B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TEMP_JOB_4_FRAMES (JobTemp) ] used: 0B | peak: 0B | reserved: 6291456B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TEMP_JOB_ASYNC (Background) ] used: 22837212B | peak: 0B | reserved: 58720256B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_GFX ] used: 67784572B | peak: 0B | reserved: 117444608B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_CACHEOBJECTS ] used: 754150190B | peak: 0B | reserved: 789327872B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_TYPETREE ] used: 3344316B | peak: 0B | reserved: 6291456B
2024/07/22 15:04:46.710 23786 24023 Error Unity [ ALLOC_PROFILER ] used: 446776B | peak: 34821100B | reserved: 50331648B
Thank you for the information. I'll review what you pointed out and make some updates accordingly.
(I'm letting you know that I've seen your message)
Temporary update, I merged your suggestion of releasing texture on main thread on destroy process and I updated native plugin (I found that some of my code was failing to free memory of some resources). Currently not checked app crash on load scene at runtime, so I set about it later. I published current once.
ps: I found multi instance problem in latest update
I got crash when testing in android. the crash caused by out of memory.
how to reproduce
doing this several times, will continously bloat up the memory then crashed![image](https://github.com/TLabAltoh/TLabWebView/assets/147171097/14485d10-e264-4b84-80c9-93ce437d297e)
This is my solution![image](https://github.com/TLabAltoh/TLabWebView/assets/147171097/7cd87bfa-6071-4b4f-a10c-7dc87b23fe5e)
appearently if we create new Texture2D() in Runtime, we need to explicitly destroy it when no longer use it, otherwise it'll be memory leak. normally it will be cleaned up everytime the scene is changed (*using single mode) but in my case, i've always loading additive scene
I see that we already released the texture in the java lib, but idk, above solution just works for me.![image](https://github.com/TLabAltoh/TLabWebView/assets/147171097/4f92e239-12df-411f-adef-f0b9429fafa1)