MediaPipeUnityPlugin
MediaPipeUnityPlugin copied to clipboard
EXC_BAD_ACCESS on iOS build (CreateCVPixelBufferForImageFramePacket crash)
Plugin Version or Commit ID
v0.9.1
Unity Version
2020.3.30f1
Your Host OS
Windows 10 Pro / Mac OS
Target Platform
iOS
Target Device
iPhone 7 plus
[Windows Only] Visual Studio C++ and Windows SDK Version
No response
[Linux Only] GCC/G++ and GLIBC Version
No response
[Android Only] Android Build Tools and NDK Version
No response
[iOS Only] XCode Version
13.3
Build Command
python build.py build --ios arm64 --linkopt=-s -vv
Bug Description
App crash within 30 seconds after inferencing. It frequently occurs on iPhone 7 plus. Currently, I haven't seen this issue on iPhone 12 and 13.
Attached files are Xcode stack trace and inspector when bug occurs.
Steps to Reproduce the Bug
- Update mediapipe version to over 0.9.0
- Build app and run on iPhone 8 or lower.
Log
.
Screenshot/Video
Additional Context
No response
Thank you for reporting the issue.
Will you test to see if this error also occurs in the official sample app (at v0.8.9)? If it also occurs, will you further test to see if it also occurs in the latest commit?
- Update mediapipe version to over 0.9.0
I'm a little curious, does that mean it doesn't happen with older versions?
@homuler It didn't happen with 0.8.3 on iPhone 7 plus (at least it didn't crash within 10 seconds). I think It is a newly occurred issue. I skipped the 0.8.4 release and upgraded to 0.9.1.
As you said (#417) https://github.com/google/mediapipe/commit/cc6a2f7af65977248b2a15f471503da2832f583a, this commit seems related to this problem. How do you manage the official MediaPipe code on this repo? Could it cause the issue?
How can I test it? Just running an official sample app on iPhone 7 plus?
Thank you so much!
How can I test it? Just running an official sample app on iPhone 7 plus?
Yes. Depending on the scene you tested, the app you build should be different (if you tested the Face Detection scene, then please build the Face Detection sample app). But if it doesn't happen with v0.8.3, the built app would likely work fine.
It didn't happen with 0.8.3 on iPhone 7 plus (at least it didn't crash within 10 seconds). I think It is a newly occurred issue. I skipped the 0.8.4 release and upgraded to 0.9.1.
I am very sorry, but if possible, I would like you to investigate which commit caused the problem using git bisect
.
I don't have an old iPhone and have no idea what caused it, so it is difficult for me to determine the cause.
If it can happen with v0.8.3, then I can think of one possible cause.
In sample scenes, input ImageFrame
is built from NativeArray<byte>
returned from Texture2D.GetRawTextureData
.
Perhaps the memory address has been changed in the middle of the process by GC, etc.
I have same issue. I build and run with two devices. iPhoneXs woks find but iPhone 6s occurred above error always.
Plugin Version or Commit ID v0.9.1
Unity Version 2021.3.1f1
Your Host OS Mac OS
Target Platform iOS
Target Device iPhone 6 s
I have the same issue. I ran it on my iPhone 7 and the error occurred always when starting the app for the first time I sometimes have to restart it like 3 times for it to work.
Plugin Version or Commit ID v0.10.0
Unity Version 2021.3.2f1
Your Host OS Mac OS / Mac M1
Target Platform iOS
Target Device iPhone 7
I'm a little curious, does that mean it doesn't happen with older versions?
Yes I was using an older version with the same phone I didn’t get this issue
Hi, homuler! I've been busy with other things lately, so I haven't been paying attention. Is there any update related to this issue?
No. As I mentioned in https://github.com/homuler/MediaPipeUnityPlugin/issues/544#issuecomment-1112074794, I don't have any devices where the issue can be reproduced. Unless someone who has those devices identifies the cause, I don't think this issue will be solved.
I built HolisticTrackingGpuApp (cause I use holistic graph) and It runs without crashing on iPhone 8 and 7 plus on https://github.com/google/mediapipe/commit/cc6a2f7af65977248b2a15f471503da2832f583a and v0.8.9
Hi Homuler! I built sample app of previous commits of this repo(MediaPipeUnityPlugin). This issue started to occur on 9d7e390. I hope this is useful to you 👍🏻
If you have any idea please let me know. Thank you:)
@siisee11 Thank you. With https://github.com/homuler/MediaPipeUnityPlugin/commit/9d7e390b6012b2f5ebed14de599d90821f4f7f62, GetTextureName
is not called until it is needed. If you call TextureFrame#GetTextureName
in TextureFrame#SetPixels32
(after _texture.Apply()
), does that solve the issue?
Unfortunately, I still have no way to fix it without devices.
For now, I'm thinking it is related to the behavior of Texture2D#GetTextureNativePtr
, but we need to find out more about what is happening on the iPhone 7.
However, since this seems to be only a sample code issue, it is not a high priority at present.
I tested your solution on the sample app and It didn't crash for an hour. I'll test it in my application. This is related to sample code, but I think many users of this plugin would utilize your sample code! I'll test further and If there is no issue I'll close this issue.
Thank you, you are the best! 👍🏻
Please leave this issue open until it's fixed in the master branch.
Of course, I'd like to fix it, but in order to merge the fix, we need a rational and logical explanation of why it will solve the problem. And as I don't have devices, I need to wait for someone to do a detailed investigation.
Sure, thank you. I'll take a closer look when I have time.
@siisee11 Could you post your solution here please?
Do you mean like this:
public void SetPixels32(Color32[] pixels)
{
_texture.SetPixels32(pixels);
_texture.Apply();
var currentName = GetTextureName(); // <- This line has been added
if (!RevokeNativeTexturePtr())
{
// If this line was executed, there must be a bug.
Logger.LogError("Failed to revoke the native texture.");
}
}
Is there any intuition what that extra line does? Could it hurt performance?
Some more info:
I could produce the bug mentioned in this issue on an Iphone 7.
I tested with following MediaPipeUnityPlugin versions:
- v0.10.1
- v0.10.3
Update: The above mentioned workaround seems to work for me as well. for whatever reason...