Question

I'm having a problem when using the Facebook Unity API, calling the FB.Feed() method. It winds up giving this error:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content,
UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at
C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:264)

which is immediately followed by:

ArgumentException: Getting control 1's position in a group with only 1 controls
when doing Repaint

I know the second error is usually caused in Unity by GUI elements changing between GUI event calls, etc. In my case, however, I'm not doing anything within OnGUI at all. In fact, because of tearing my hair out trying to figure out what the problem is, I created a totally new project - 1 scene with basic buttons to login, and then "brag" using the FB.Feed. I've written it the exact way that their documents show, and I get the exact same error.

I'm hoping maybe someone might be able to shed some light on what I'm missing or doing wrong.

Here is complete code in my simple barebones scene that also causes this error:

void Start()
{
    FB.Init(OnInitComplete, OnHideUnity);
}

void OnInitComplete()
{
    Debug.Log("FB Initialized");
}

    void OnHideUnity(bool isGameShown)
    {
        Debug.Log("OnHideUnity");
        if (!isGameShown)               
            Time.timeScale = 0;
        else
            Time.timeScale = 1;
    }

    void Update()
    {

    }

    void OnGUI()
    {
        if (!FB.IsLoggedIn)
        {
            if (GUI.Button(new Rect(10, 10, 100, 30), "Login"))
                FBLogin();
        }
        else
        {
            if (GUI.Button(new Rect(10, 50, 100, 30), "Brag"))
            {
                Brag();
            }
        }

    }

    void Brag()
    {
        FB.Feed(
            linkCaption: "This is testing the testapp FEED",
            picture: "http://myapp.com/myapplogo.jpg",
            linkName: "Foo Link",
            link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
            ); 
    }

    void FBLogin()
    {
        FB.Login("email, publish_actions", OnLoggedIn);
    }

    void OnLoggedIn(FBResult result)
    {
        if (FB.IsLoggedIn)
            Debug.Log("Logged in successfully");
    }

My Facebook API is version 140220, and my Unity is 4.3.4

I'll do my best to answer any other questions for info I've missed

I've also tried using the FB API version 131022, and have the same results.

This error also happens with the FriendSmash example and as well with the InteractiveConsole example scene provided with the plugin.

I should also point out that the Window does open for the post, and loads the image, link, etc. The exception prevents anything else from working however

Additional Info: I've found that when the app is ran on an actual android device, the feed post works with no problem. It only appears to have this error within the Unity editor. I have another issue with test users logging in on the android device - they can't if the device has the Facebook app itself installed, but that issue probably warrants a separate question

Was it helpful?

Solution

I think it's just not getting all of the resources it's asking for. The docs say not to worry about it, the editor can only do so much. I get the one below. Unfortunately though, mine is not working on the device, but if yours is, I wouldn't worry about it too much.

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:264)
UnityEngine.GUILayoutUtility.GetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:257)
Facebook.FbSkinnedDialog.TwoButtonBar (System.String label, System.String cancelLabel)
Facebook.FeedDialog.UpdateDialog (Int32 windowID)
Facebook.FbSkinnedDialog.GeneralUpdateDialog (Int32 windowId)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUI.cs:1395)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top