Results 1 to 10 of 10

Thread: Stack Overflow

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    67

    Stack Overflow

    Working on a large app that now presents me with error 28 - stackoverflow

    I cannot find where this is being caused.
    I have error traps all over but the error is thrown at different places so it is difficult to see what is causing it.

    Is there VB6 code that will get me a view of the stack or something relted so I can see when the stack is growing ?

    Any clues will be helpful.
    Thank you.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,119

    Re: Stack Overflow

    In the error message press the Debug button. Then press Control+L

    There you'll be able to see which procedure is calling itself.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Stack Overflow

    Also,

    Code:
    Debug.Print "something identifying spot"
    ... is also helpful. I suspect you have at least some idea as to what procedure(s) are recursing.

    Also, error trapping isn't going to help you much with stack overflow. When you overflow the stack, the only thing that's going to help is unwinding (returning from the called procedure(s)) it.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    67

    Re: Stack Overflow

    Unfortunately none of the above helped.

    I did find the problem. While moving the mouse I was doing many things including displaying some values on th form using labels.

    I was moving the mouse to fast for the IDE to catch up.

    I put a catch in the method doing the label filling to not fill if already in that method.
    That solved the problem.

    I will eventually change the the code to use a timer to handle writing to these labels and that will quell the high activity.

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,654

    Re: Stack Overflow

    Quote Originally Posted by LorinM View Post
    I did find the problem. While moving the mouse I was doing many things including displaying some values on th form using labels.

    I was moving the mouse to fast for the IDE to catch up.
    That wouldn't cause a stack overflow error. The IDE has no problems updating Label values on MouseMove no matter how fast the mouse moves.

    Stack overflows are usually caused by unrestrained recursion. Likely in making those changes you accidentally corrected the actual problem.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Junior Member
    Join Date
    Jun 2017
    Posts
    27

    Re: Stack Overflow

    When I saw the subject my first thought went to Joel Spolsky.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,146

    Re: Stack Overflow

    Yeah, me too.

    Niya's right, though, the IDE can't very well be bothered by moving the mouse too fast. If that was even a reasonable issue, we'd have programs and Windows itself, falling over every day. The solution sounds right, but the underlying problem is wrong. You have set up a recursive call. By checking whether or not execution is already in the method, you have solved the recursion, but a better solution would be to figure out why it was happening in the first place.
    My usual boring signature: Nothing

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Stack Overflow

    Quote Originally Posted by Niya View Post
    That wouldn't cause a stack overflow error. The IDE has no problems updating Label values on MouseMove no matter how fast the mouse moves.
    Whenever my mind starts thinking like that, I remind myself that VB6 is single-threaded.

    Regarding updating labels, they're not going to get updated until you return control to Windows, and then those internal "refresh" events will be raised with the label captions refreshing. Or, if you do MyLabel.Refresh, that's like making a call to the label's refresh code, which won't return until the label has been refreshed. VB6 just can't do two-things-at-once.

    ------------

    Now, the mouse, that's a different issue. Mouse movement isn't handled by our VB6 thread. It's handled by a high-priority thread that's setup by Windows. And I've never seen a problem with that. In fact, that has absolutely nothing to do with our VB6 stack, or even any of our VB6 code.

    You may say, "but we have a Mouse_Move event". Sure, Windows will try to send messages (think "events") to any hWnd that the mouse is over, and those events will be raised in our thread. However, if we're in a long-running loop, not even those will be raised because we're dominating the thread, so no other events can be raised.

    ------------

    I too agree that you've got some recursion going on. However, it's not difficult to have some recursion, even when we didn't explicitly do it. For instance, let's take a Form1 with a single textbox (Text1) on it. The following code will recurse the moment you type a 6th character in the textbox, and almost instantly overflow the stack.

    Code:
    
    Option Explicit
    
    Private Sub Text1_Change()
        If Len(Text1.Text) > 5 Then Text1.Text = "asdfasdf" & Rnd
    End Sub
    
    
    So, I suppose there's explicit recursion and also implicit recursion (the above code). But both will overflow the stack. And that's about the only thing that will. In theory, making too many calls to different functions can do it (with lots of arguments), but I've made LOTS of deep calls with LOTS of arguments, and I've never had that overflow the stack.
    Last edited by Elroy; Apr 18th, 2024 at 05:00 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,654

    Re: Stack Overflow

    Quote Originally Posted by Elroy View Post
    I too agree that you've got some recursion going on. However, it's not difficult to have some recursion, even when we didn't explicitly do it. For instance, let's take a Form1 with a single textbox (Text1) on it. The following code will recurse the moment you type a 6th character in the textbox, and almost instantly overflow the stack.

    Code:
    
    Option Explicit
    
    Private Sub Text1_Change()
        If Len(Text1.Text) > 5 Then Text1.Text = "asdfasdf" & Rnd
    End Sub
    
    
    So, I suppose there's explicit recursion and also implicit recursion (the above code). But both will overflow the stack. And that's about the only thing that will. In theory, making too many calls to different functions can do it (with lots of arguments), but I've made LOTS of deep calls with LOTS of arguments, and I've never had that overflow the stack.
    This is my thought too. It's very easy to unintentionally stumble into recursion messing around with control events. Lord knows I have done so many many times.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Stack Overflow

    And just as a further FYI, if you don't want recursion, and you think you've accidentally caused it, it's fairly easy to stop:


    Code:
    Option Explicit
    
    Private Sub Text1_Change()
        Static bRecursing As Boolean
        If bRecursing Then Exit Sub
        '
        bRecursing = True
        If Len(Text1.Text) > 5 Then Text1.Text = "asdfasdf" & Rnd
        bRecursing = False
    End Sub
    Now that's something I've done quite often, especially on something like TextBox validation, but also in other cases as well.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width