Atkelar (atkelar) wrote,

Derp moment of the day...month...year?

Sometimes it's hard to describe the amount of facepaw that a simple coding error can cause. For the last two days I was hunting down an annoying bug in one of my larger pet projects. It caused the same component of code to work under one condition but not under the other.

More precisely, I had programmed a class to hold - amongst other things a list of certain items. This list is stored in a custom built collection. Adding items to the objects worked just fine, clearing the list however left the items in place in the user interface (WPF data binding). The items are "ranges" - i.e. x/y w/h rectangles - that should be superimposed over a bitmap to indicate "used areas" of an image. Once a new area was used, it showed up right then and there. But when refreshing the information from the database (i.e. clearing the list of areas) the old information just stuck there until the program got restarted.

After debugging and even single stepping over the code I finally found out just where the error was... It boils down to this little gem here - but of course all the parts were all over the place, hidden between about 1k likes of other code. Note that this isn't the exact code but rather a brief summary:
  private UsedAreaCollection _Ranges;
  public UsedAreaCollection UsedRanges
      return _Ranges;

  private List _UsedRanges;

  public void Add(UsedArea newArea)

  public void Refresh()
    _UsedRanges = new List();

I was suspecting the data binding because I wrote a custom converter that created a BitmapSource object from the UsedAreaCollection and that was bound to the Source property of an Image. It actually works like a charm... but only when actually MODIFYING THE RIGHT COLLECTION.

This - again - is a good example of where unit testing could have pointed me to the right direction way ahead of time. Because then I would have realized that the actual property didn't change at all.
Tags: c#, coding, derp, techtalk

  • Meme, re-done: Soundtrack of your life

    I re-did the old "soundtrack of your life" meme because I still think it's funny and - depending on the size of your music collection - won't get old…

  • Music Meme...

    OK, seen this done by henriekeg and karpour... looks kind of fun, so here goes: Music Meme: Step 1: Put your iTunes or…

  • Meme?

    In memory of family and friends who have lost the battle with cancer; and in support of the ones who continue to conquer it! Post this on your LJ if…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded