Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use the AR camera I can't use the method "GetImageFromGallery" to select the picture, and call back is null #323

Open
RobinGitNa opened this issue Jun 13, 2024 · 13 comments

Comments

@RobinGitNa
Copy link

After careful investigation, the problem was found in the NGMediaReceiveCallbackiOS class,
private void Update()
{
if( IsBusy )
{
if( Time.realtimeSinceStartup >= nextBusyCheckTime )
{
nextBusyCheckTime = Time.realtimeSinceStartup + 1f;

				if( _NativeGallery_IsMediaPickerBusy() == 0 )
				{
					IsBusy = false;

					NativeGallery.MediaPickCallback _callback = callback;
					callback = null;

					NativeGallery.MediaPickMultipleCallback _callbackMultiple = callbackMultiple;
					callbackMultiple = null;

					if( _callback != null )
						_callback( null );

					if( _callbackMultiple != null )
						_callbackMultiple( null );
				}
			}
		}
	}

So I would like to know what the above method means, and will it have any effect after disabling it?Thank you so much!

@yasirkula
Copy link
Owner

It invokes the callback if the native image picker is silently closed. Can you describe the image picker UI's behaviour with and without this code?

@RobinGitNa
Copy link
Author

with this code:When I use the AR camera I can't use the method "GetImageFromGallery" to select any picture, and call back is null,But I found that I can open the phone album normally, and there is a picture path back before update method runs;
without this code : I can open the phone album normally, and there is a picture path back,and nothing else out of the ordinary.

@yasirkula
Copy link
Owner

Thank you for the elaboration.

But I found that I can open the phone album normally, and there is a picture path back before update method runs

What I understand here is that the callback is invoked with a proper path before that Update method runs?

@RobinGitNa
Copy link
Author

Yes, I'm sorry I'm not good at English.
This is because the condition "_NativeGallery_IsMediaPickerBusy() == 0" is always true after opening the AR camera。
In short, after the Update method is commented out, the image path can be obtained, and this phenomenon only occurs in ios, and the image path can be obtained even if the AR camera is opened in Android。

@yasirkula yasirkula reopened this Jun 14, 2024
@yasirkula
Copy link
Owner

I couldn't give it a thought due to my current schedule. This is still in my mind.

@RobinGitNa
Copy link
Author

I couldn't give it a thought due to my current schedule. This is still in my mind.

Thank you very much

@yasirkula
Copy link
Owner

I'm trying to pinpoint the root of the issue. Were you testing on an iPad? If so, did the problem occur on an iPhone, as well?

@RobinGitNa
Copy link
Author

I only tested it on an iPhone.

@yasirkula
Copy link
Owner

Can you put NSLogs inside this function to see how it returns 0:

+ (int)isMediaPickerBusy
{
if( imagePickerState == 2 )
return 1;
if( imagePicker != nil )
{
if( imagePickerState == 1 || [imagePicker presentingViewController] == UnityGetGLViewController() )
return 1;
else
{
imagePicker = nil;
return 0;
}
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
else if( CHECK_IOS_VERSION( @"14.0" ) && imagePickerNew != nil )
{
if( imagePickerState == 1 || [imagePickerNew presentingViewController] == UnityGetGLViewController() )
return 1;
else
{
imagePickerNew = nil;
return 0;
}
}
#endif
else
return 0;
}

For starters, you should log imagePickerState, whether or not imagePicker/imagePickerNew is nil, whether or not its presentingViewController is UnityGetGLViewController() (if not, what is it? Is it nil?)

@RobinGitNa
Copy link
Author

sorry,I was very busy recently. I ran some tests, but they didn't seem out of the ordinary, did they?
code:

  • (int)isMediaPickerBusy
    {
    NSlog(@"imagePickerState:%d",imagePickerState);
    if( imagePickerState == 2 )
    return 1;

    NSlog(@"imagePicker != nil:%d",imagePicker != nil );
    if( imagePicker != nil )
    {
    NSlog(@"imagePicker :%@",imagePicker);
    if( imagePickerState == 1 || [imagePicker presentingViewController] == UnityGetGLViewController() )
    return 1;
    else
    {
    imagePicker = nil;
    return 0;
    }
    }
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
    NSlog(@"14.0--imagePickerState:%d",imagePickerState);
    NSlog(@"14.0--imagePickerNew != nil:%d",imagePickerNew != nil);
    else if( CHECK_IOS_VERSION( @"14.0" ) && imagePickerNew != nil )
    {
    NSlog(@"14.0--imagePickerNew:%@",imagePickerNew);
    if( imagePickerState == 1 || [imagePickerNew presentingViewController] == UnityGetGLViewController() )
    return 1;
    else
    {
    imagePickerNew = nil;
    return 0;
    }
    }
    #endif
    else
    return 0;
    }

test result:

imagePickerState:1
imagePicker != nil:0
14.0--imagePickerState:1
14.0--imagePickerNew != nil:1
14.0--imagePickerNew :<PHPickerViewController: 0x125b34490>
imagePickerState:0
imagePicker != nil:0
14.0--imagePickerState:0
14.0--imagePickerNew != nil:1
Picked an image
/var/mobile/Containers/Data/Application/CE9F5A69-F226-487D-808E-291FED04C802/Library/Caches/pickedMedia1.heic -- imgName :pickedMedia1_1719390587686.000.heic ---length:13698421
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
ARPlace_ImageView:b__8_0(String)
NativeGalleryNamespace.NGMediaReceiveCallbackiOS:OnMediaReceived(String)

@yasirkula
Copy link
Owner

Yes it looks ordinary. I was suspecting that the imagePicker's presentingViewController check was somehow failing in AR but the logs say otherwise. I'll investigate the parts where imagePickerState is set to 0. Were you receiving the null callback immediately after invoking GetImageFromGallery or after picking an image from the gallery?

@RobinGitNa
Copy link
Author

Yes,I received the null callback immediately after picking an image from the gallery.
Sorry, I don't have a mac , I can't provide more information about the test.

@yasirkula
Copy link
Owner

Hello again. I'm trying to debug this issue once again. On AR, does the app pause/stop while the image picker is visible? If you get the chance, could you put Debug.Log(Time.frameCount) inside NGMediaReceiveCallbackiOS.Update and NGMediaReceiveCallbackiOS.OnMediaReceived so that we can understand which one is called when?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants