fehaar / FFWD

This is the FFWD framework for XNA, that allows you to port Unity3D games to XNA for use on WP7 or XBox360 (XBLIG)
Microsoft Public License
133 stars 36 forks source link

I Solved issue that some might get. #73

Closed stanleyjoy closed 11 years ago

stanleyjoy commented 11 years ago

Got a funky bug...

When I was jumping between scenes, the game crashes. [Menu -> Game -> Menu -> (Crash)]

It is pointing a Null Reference error to Compare Tag method in the Component.cs

Check Code

Component.cs

region Public methods

    public bool CompareTag(string tag)
    {
          return gameObject.CompareTag(tag);                 // NULL ISSUE FIRES HERE
    }

endregion

While debugging the return boolean of that method is a null at the point of crash.

The solution. I think the Component.cs is called or compiled before the GameObject.cs which causes the null reference issue. All we need to do is to check if gameObject is not null

Component.cs

region Public methods

    public bool CompareTag(string tag)
    {
        if (gameObject != null)                                      // If condition to check if gameObject is not null
        {
            return gameObject.CompareTag(tag);
        }
        return false;
    }
    #endregion

Using the if condition solves this issue. All though still no idea whether we would have any side effects.

Stan

If any please Post em.

fehaar commented 11 years ago

It sounds like you are tyring to call CompareTag on a component that has been destroyed. Are you doing it on a cached component reference? Checking for null is a valid method of preventing a crash though.

stanleyjoy commented 11 years ago

I was not using the compare tag at all. you can try it if you want. if it means anything the Tag that it always tries to compare is the Main Camera. Stan