• 0

It's one of those days


Question

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.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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?

Link to comment
Share on other sites

  • 0

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 :)

Link to comment
Share on other sites

This topic is now closed to further replies.