Jump to content



Photo

It's one of those days

c#

  • Please log in to reply
5 replies to this topic

#1 sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 01 October 2013 - 17:55

You guys ever have one of those days where you are programming a big project and all of the sudden you come across a bug that you can't figure out where it's coming from? It's one of those days for me. I have a class object being passed in an event and all of the sudden the class object has been modified o_O. I've used the stack trace, checked the hash codes which are the same and nothing is adding up on what is altering the object as it is being raised in the event handler. I'm so confused!!! >< Something is changing it I just can't figure out what.




#2 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 14
  • Joined: 26-October 05

Posted 01 October 2013 - 19:42

Is it really the same object (check the object ID in the debugger)? If a property is being set, put a breakpoint in the setter. If it's a mutable public field, well you can't debug that (that's what you get for using mutable public fields :p). If it's a private method changing a private field, put breakpoints in every private field assignment of the class.

 

There are only so many ways an object can change. Nail down which one it is and get a breakpoint in the right place.



#3 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 01 October 2013 - 20:06

Additionally, isn't that what watchpoints are for? Set a breakpoint where you instantiate the object, then tell the debugger to watch it. You will be notified every time it is modified and given a chance to inspect the environment thereafter. Failing that, if you have set methods for it, I think Asik's suggestion is also very good.



#4 OP sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 01 October 2013 - 20:25

I finally figured it out :) Basically, I had another method that I was overlooking that modified it unintenally in the event constructor parameter.



#5 firey

firey

    F͎̗͉͎͈͑͡ȉ͎̣̐́ṙ͖̺͕͙̓̌è̤̞͉̟̲͇̍̍̾̓ͥͅy͓̍̎̌̏̒

  • Tech Issues Solved: 8
  • Joined: 30-October 05
  • Location: Alberta, Canada
  • OS: Windows 7
  • Phone: Android (4.4.2)

Posted 01 October 2013 - 20:25

What is changing?

Are member variables being changed?
Are you passing the object directly? If so remember it will be that object and not an instance of it.  
Are you modifying the object when it is passed?

Are you passing the right object?

How do you know it is changing?



#6 OP sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 04 October 2013 - 03:32

Basically, there was a class that took it in as a parameter when I rewrote some code and I forgot that class would alter the results >< The stack trace didn't show that when the break points were being hit. I figured it out by going line by line each time the variable was referenced. I knew it was changing because the object contained a dictionary and that dictionary would be cleared out by the time the event was triggered. I had just been staring at code for so many hours it all started to blend together. But posting the problem on here cleared my thoughts so thanks guys :)