Author Topic: PPtr cast failed when dereferencing!  (Read 13290 times)

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
PPtr cast failed when dereferencing!
« on: July 05, 2012, 02:02:48 AM »
When I move NGUI window(e.g. Atlas Maker), error message shows.

PPtr cast failed when dereferencing! Casting from Shader to MonoBehaviour!
UnityEditor.DockArea:OnGUI()

What does it mean?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PPtr cast failed when dereferencing!
« Reply #1 on: July 05, 2012, 02:03:45 AM »
No idea. I've never seen it before, but it sounds like some issue in the unity editor.

J. Park

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: PPtr cast failed when dereferencing!
« Reply #2 on: July 05, 2012, 02:10:52 AM »
It may be result from my other plugin.

Thanks.

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: PPtr cast failed when dereferencing!
« Reply #3 on: November 30, 2012, 09:40:28 PM »
Hey guys

I am experiencing the same issue intermittently. After some event occurs (whatever that might be) dragging the tabs of any editor windows will repeatedly display that error message in the console.

The error message always appears to repeat the exact same message on each line in the console. Though under different occasions the error varies:

  1. PPtr cast failed when dereferencing! Casting from Shader to MonoBehaviour!
  2. UnityEditor.DockArea:OnGUI()
  3.  
  4. PPtr cast failed when dereferencing! Casting from Mesh to MonoBehaviour!
  5. UnityEditor.DockArea:OnGUI()
  6.  
  7. PPtr cast failed when dereferencing! Casting from Prefab to MonoBehaviour!
  8. UnityEditor.DockArea:OnGUI()

Was any progress made on this previously?

Any ideas as to how I might track this issue down?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PPtr cast failed when dereferencing!
« Reply #4 on: December 01, 2012, 11:33:23 AM »
I've never seen it, but a wild guess here -- did you have a public member variable on one of your scripts that was one component type (ie: Mesh for example), and later you changed it to be another (ie: MonoBehaviour), keeping the same variable name?

dlewis

  • Guest
Re: PPtr cast failed when dereferencing!
« Reply #5 on: December 02, 2012, 05:10:37 AM »
I occasionally see an 'OnPaint mismatch' for the GUI on Unity4 (I assume GUI.BeginX and then returning before a matching GUI.EndX), maybe it's related to that.

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: PPtr cast failed when dereferencing!
« Reply #6 on: December 02, 2012, 01:47:45 PM »
@ArenMook I have double checked my scripts but I cannot find any places where this might be an issue. By the way, this is probably not an issue with NGUI (even though I am using NGUI). I came across this thread and was hoping that there was an obvious solution.

I think that I have introduced this issue into one of my scripts. It doesn't seem to occur very frequently (which is a shame because that would make it easier to diagnose).

@dlewis If the error is because of GUI.BeginX and GUI.EndX then you might find that you just need to use EditorGUI.ExitGUI(); when you handle things like button clicks. In fact I find that the following is generally good practice because it avoids these issues:

  1. if (GUILayout.Button("Click Me")) {
  2.     // Do your stuff!
  3.     EditorGUI.ExitGUI();
  4. }