Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Strategy For Avoiding Stack Overflow

Sign in to follow this  


Okay, so I have a ByteAddress class, as well as ByteRegister and WordRegister classes.

Each of these has an event that can be set to call a function that gets sent a reference to the object that had the event.

Now, the event fires off when the value of the register is set. Not changed, set. If the value is 23, and something sets the value to 23, the event fires off. Yes, there is a valid reason for this.

The problem is that the functions called by these events may want to set the value of the object to something else, which would cause the event to fire again(as far as I understand it), and thus potentially cause a stack overflow.

So, my thoughts thus far are: a) disable the event handler temporarily while dealing with the event, or b) have an alternate way of setting the value.

And, of course, in the course of writing this post, I have the solution... simply send a reference to the member containing the value to the function called by the event. That way, the event has a specific way to change the value that doesn't fire off the event.


Problem solved. Thanks for your help.
Sign in to follow this  


Recommended Comments

I run into this problem when I write custom input handlers for TextBox's. They re-modify input based on what the user types in... but unfortunately re-modifying the text causes the event to fire again...

So I use an internal boolean to determine if the function should immediately exit. Not terribly elegant, true, but it works.

Share this comment

Link to comment
Yeah, my first thought was to come up with a way to hook and unhook the handler, or disable/reenable the handler, or just in some way not have the handler pick up a change within a designated time period.

Which is why I decided to go with sending a byte reference to the handler. I can then circumvent the process that triggers the handler. Yay for me!

Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!