Sign in to follow this  

It's one of those days

Recommended Posts

sathenzar    23

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.

Share this post


Link to post
Share on other sites
+Andre S.    1,892

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.

Share this post


Link to post
Share on other sites
Karl L.    275

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.

Share this post


Link to post
Share on other sites
sathenzar    23

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

Share this post


Link to post
Share on other sites
firey    3,631

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?

Share this post


Link to post
Share on other sites
sathenzar    23

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.