Bug variable was declared outside lock context block

2 posts, 1 answers
  1. Blamara
    Blamara avatar
    10 posts
    Member since:
    Dec 2014

    Posted 05 Apr 2015 Link to this post

    pretty formating is little buggy, maybe you should leave it as is ;)

    if we declare variable outside lock, then do something inside lock, and later invoke it on another thread decompiled code is broken.

    Original code:

    class OutsideLock : UserControl
    {
      ulong IamClassMember = 0;
      private void DrawBackgroundAsync()
      {
        ulong IamOutsideLock;
        lock (this)
        {
          ++this.IamClassMember;
          IamOutsideLock = this.IamClassMember;
        }
        // Util.DoAllDrawEvents(this.myImage.Dispatcher);
        int width = (int) Math.Round((double)this.Width);
        int height = (int) Math.Round((double)this.Height);
        ThreadPool.QueueUserWorkItem((WaitCallback) (param0 => this.DoDrawWork(IamOutsideLock, width, height)));
      }
     
      private void DoDrawWork(ulong iDraw, int width, int height)
      {
        // bla
      }
    }

    Decompiled code:
    internal class OutsideLock : UserControl
    {
        private ulong IamClassMember;
     
        public OutsideLock()
        {
        }
     
        private void DoDrawWork(ulong iDraw, int width, int height)
        {
        }
     
        private void DrawBackgroundAsync()
        {
            lock (this)
            {
                OutsideLock iamClassMember = this;
                iamClassMember.IamClassMember = iamClassMember.IamClassMember + (long)1;
                ulong num = this.IamClassMember;
            }
            int num1 = (int)Math.Round((double)base.Width);
            int num2 = (int)Math.Round((double)base.Height);
            ThreadPool.QueueUserWorkItem((object param0) => this.DoDrawWork(num, num1, num2));
        }
    }

    as you can see there is no variable declaration before lock context block, instead its moved inside lock context block.
    resulting in error in compiler since call to DoDrawWork is outside lock context block:
    >> error CS0103: The name 'num' does not exist in the current context

    also what is that italic text!?
    what have you done with increment?

  2. Answer
    Alexander
    Admin
    Alexander avatar
    80 posts

    Posted 07 Apr 2015 Link to this post

    Hi Blamara,

    Thank you for letting us know about this problem.

    The bug is added to our backlog and will be fixed as soon as possible.

    Please, update regularly and stay tuned.

    Regards,
    Alexander
    Telerik
  3. DevCraft banner
Back to Top