Author Topic: Temporary bug fix for null reference crash in UIDrawCall.UpdateGeometry  (Read 1824 times)

alexkring

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 3
    • View Profile
NGUI Version: 3.7.4 (looking at the code, it looks like it also exists in 3.9)

Bug: 'panel' is null, inside UIDrawCall.cs, in the function UpdateGeometry, in this block of code:

  1. // Non-automatic render queues rely on Z position, so it's a good idea to trim everything
  2.                                 if (!trim && panel.renderQueue != UIPanel.RenderQueue.Automatic)
  3.                                         trim = (mMesh == null || mMesh.vertexCount != verts.buffer.Length);

Temporary Fix: Add the following code at the top of the UpdateGeometry function in UIDrawCall.cs

  1. if ( panel == null )
  2.                 {
  3.                         return;
  4.                 }

This would occasionally happen in our game, when the user would press a UI button that restarted the game. In the case of the bug, the OnDisable is called on the UIDrawCall object (since the game is closing), which sets panel to null. Then the parent panel calls UpdateGeometry in the same frame, which originates from the LateUpdate function of the panel.

I consider the fix above a hack, because it doesn't actually fix all of the potential bugs, it only fixes the bug I described. The real fix should be this: all of the public functions check to see if the object is disabled (including the public static functions), and respond to this state accordingly. In most cases, the functions should not be called when the object is disabled.

Would it be possible to get a real fix for this, in a future release? Thanks!
« Last Edit: July 14, 2015, 05:50:48 PM by alexkring »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Sure, I'll add the null check. Thanks!