Plugin and Pointer

Sorry about the big title but what I’m trying to do is (or should be) quite simple, to get multiple results from one plugin call.

My plan was to use pointers, and I did a little test, with a scenario where it pulls both system time and the other player’s state in one call.

In the C# interface:

	[DllImport ("__Internal")]
	private static extern double _GetTime (IntPtr peerState);

	public static double GetTime(IntPtr peerState)
	{
		if (Application.platform != RuntimePlatform.OSXEditor){
			return _GetTime(peerState);
		}else{
			return 0;
		}
	}

In Objective C implementation:

	double _GetTime(int* peerState)
	{
		*peerState = 5; 
		return [delegateObject getTime];
	}

The code broke at the assignment line:

	*peerState = 5;

Giving me:
Program received signal: “SIGBUS”.
Previous frame inner to this frame (gdb could not unwind past this frame)
Previous frame inner to this frame (gdb could not unwind past this frame)

Can anyone help me with this?? :shock:

I can’t lay my hands on anything definitive, but is this definitely a case for IntPtr and not a ref parameter?

By ref parameter you meant the normal pointers? Like

MyObjectClass* myObject;

From what I gathered (I’m new to C# U_U), things like this are “unsafe” (?) or need to be marshaled? I’m not familiar with either so I used the IntPtr provided by System.

Solved this case by using struct.

Seems like IntPtr in C# and int* in xcode are two different things and cannot be passed directly from one to another. Still curious to know how others are playing with pointers tho…

Hi,
if you need to return two values from a function I would recommend to create structure with two fields and return it by value.