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

Vector2 converter not working on iOS #63

Open
unnanego opened this issue Sep 30, 2021 · 7 comments
Open

Vector2 converter not working on iOS #63

unnanego opened this issue Sep 30, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@unnanego
Copy link

I have both packages (latest versions) installed from the jilleJr source. It works fine in the editor, but gives the "self referencing" error on iOS. Unity version 2020.3.18f

@applejag
Copy link
Owner

Hi @unnanego! Thanks for reaching out :)

I'm lacking context through. The error message is too general.

Could you supply me with the full error message? I know it's tricky to get it from the phone, but if you could get the errors forwarded to your editor then you can copy it from the logs there.

If you could provide the C# types you are trying to use as well that would help a lot.

And does the error occur on serialization (to-string) or deserialization (from-string)?

@unnanego
Copy link
Author

unnanego commented Sep 30, 2021

JsonSerializationException: Self referencing loop detected for property 'normalized' with type 'UnityEngine.Vector2'. Path '[0].AutoPoint'.
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContainerContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract& memberContract, System.Object& memberValue) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, System.Collections.IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <00000000000000000000000000000000>:0 
  at Location.SaveJson () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()

@unnanego
Copy link
Author

unnanego commented Sep 30, 2021

It happens on serialization.

The type:

public struct Coordinates
{
	public float Latitude
	{
		get;
	}

	public float Longitude
	{
		get;
	}

	public Vector2? AutoPoint;
	public Vector2? ManualPoint;

	public Coordinates(float latitude, float longitude)
	{
		Latitude = latitude;
		Longitude = longitude;
		AutoPoint = new Vector2(0f, 0f);
		ManualPoint = null;
	}
}

@applejag
Copy link
Owner

Awesome, thanks for clarifying!

My guess is that this is caused by the Converter getting stripped out as it's not explicitly referenced.

Try save the following as link.xml anywhere in your Assets directory, such as directly at Assets/link.xml:

<linker>
    <assembly fullname="Newtonsoft.Json.UnityConverters" />
</linker>

If that solves the issue, then I can update the Newtonsoft.Json-for-Unity.Converters package so the stripping is disabled by default.


If you want to know more about this stripping mechanic of the compilation process, I recommend the following documents:

@applejag applejag self-assigned this Sep 30, 2021
@applejag applejag transferred this issue from applejag/Newtonsoft.Json-for-Unity Sep 30, 2021
@unnanego
Copy link
Author

Yes, it did the trick, thank you!

@applejag
Copy link
Owner

I'm reopening this and using it to track that I need to fix this permanently.

I've also moved this issue the converters repo.

If you stay subscribed to this issue, then you can get a notification when this has been fixed with a new version, and can then remove that link.xml hack.

@Wobling
Copy link

Wobling commented Feb 29, 2024

Just came across this when building for WebGL.
The stripping was indeed the issue, thanks for the solution, and thanks for your hard work supporting this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants