|
-
Apr 5th, 2024, 01:27 PM
#1
Thread Starter
PowerPoster
[Resolved - I'm stupid] Going out of scope before it should be
tl;dr.
I thought a thing should be on the stack but the procedure exits before going back to the caller and takes itself off the stack like it's supposed to. There is no bug.
======================================================
I posted my CallStack demo in the code bank and I've been trying to clean it up to repost and found a pretty nasty bug.
Specifically I am creating an object in a procedure that when it goes out of scope, the object is destroyed and it pops itself off the callstack.
But what's happening is that it's doing that when I think it's still supposed to be in scope.
What am I doing wrong?
Also happening when cmdExit_Click is called so neither the Hourglass or cmdExit_Click event are on the stack when they should be.
The CallStack is behaving as it should. I single-stepped through it and it's incrementing the array of calls properly.
And AddToCount is getting put on the stack properly.
So what I am getting is this:
52440.283 frmCallStackDemo.cmdStartCounting(Private Sub)
52440.283 frmCallStackDemo.AddToCount(Private Sub)
' 50 more AddToCount calls follow
What I should be getting is this:
52440.283 frmCallStackDemo.cmdStartCounting(Private Sub)
#####.### cHourglass.Hourglass(Public Sub)
51 stacks of AddToCount
##### frmCallStackDemo.cmdExit_Click(Private Sub) ' Ignore this. This isn't a problem. It shouldn't be on the stack because it exits and takes itself off the stack before coming back to the cmdStartCounting sub. so that's not an issue. It's just the hourglass.
Code:
Private Sub cmdStartCounting_Click()
Dim m_CallStacker As New cCallStacker
Dim Hourglass As New cHourglass
m_CallStacker.Add Me.NAME & ".cmdStartCounting(Private Sub)"
Hourglass ' Right here. This is going out of scope immediately after being called instead of when the Sub exits.
' Hourglass cursor is still active but it called its class_terminate event already but still shows an hourglass. Makes no sense.
' When this procedure exits it turns the mousepointer back like it should. It's weird.
nCount = 0
AddToCount
cmdExit_Click
End Sub
'======================
Private Sub AddToCount()
Dim m_CallStacker As New cCallStacker
m_CallStacker.Add Me.NAME & ".AddToCount(Private Sub)"
If nCount = 50 Then Exit Sub ' Exit condition.
Sleep 25 ' Slow it down.
nCount = nCount + 1
lblCount.Caption = nCount
DoEvents ' Refresh the Label.
AddToCount ' Recursively call self to Pump Up the CallStack, baby!
End Sub
======================
' cHourglass Class:
Option Explicit
Public Sub Hourglass(Optional ByVal SetHourglass As Boolean = True) ' Default Class Property.
Dim m_CallStacker As New cCallStacker
m_CallStacker.Add NAME & ".Hourglass(Public Sub)"
If SetHourglass = False Then
Screen.MousePointer = vbNormal
Else
Screen.MousePointer = vbHourglass
End If
DoEvents
End Sub
Private Sub Class_Terminate()
Dim m_CallStacker As New cCallStacker
m_CallStacker.Add NAME & ".Class_Terminate(Private Sub)"
Screen.MousePointer = vbNormal
End Sub
Last edited by cafeenman; Apr 5th, 2024 at 03:15 PM.
-
Apr 5th, 2024, 01:35 PM
#2
Thread Starter
PowerPoster
Re: Going out of scope before it should be
Things I've tried.
I commented out the Doevents in the Hourglass sub just considering maybe something weird was going on but didn't expect that to fix it which it didn't.
Also tried declaring Hourglass as cHourglass and then separately making it a new cHourglass.
Dim Hourglass as cHourglass
Set Hourglass = New cHourglass
also didn't fix it.
I'm perplexed.
-
Apr 5th, 2024, 02:01 PM
#3
Thread Starter
PowerPoster
Re: Going out of scope before it should be
OK, I think that's not the problem. It goes out of scope when I single step but when I set a breakpoint in the class terminate event of the hourglass it doesn't get called until the sub that called it exits so the problem is probably somewhere else.
I would say there's a problem in the callstack class but since it's putting AddToCount on the stack properly with the correct number of stacks then I'm not sure what the problem is.
-
Apr 5th, 2024, 02:10 PM
#4
Thread Starter
PowerPoster
Re: Going out of scope before it should be
Actually, now that I think about it, cmdExit_Click shouldn't be on the stack because it exits and takes itself off the stack before coming back to the procedure that called it so that's not a problem. It's just the hourglass.
Also, there's construction right next to my bedroom wall and I should have been asleep hours ago. So I'm kind of foggy. I should look at it again after I get some sleep.
But still there's something going on that's not putting the hourglass on the stack unless my brain-fog isn't seeing why it shouldn't be on the stack and this isn't even a problem.
-
Apr 5th, 2024, 02:21 PM
#5
Thread Starter
PowerPoster
Re: Going out of scope before it should be
Duh...
It's working fine. Never mind. When Hourglass exits it takes itself off the stack.
All is well. I'm just having a brain malfunction.
Sorry to bother everyone. 
I'm a happy guy.
-
Apr 5th, 2024, 02:30 PM
#6
Thread Starter
PowerPoster
Re: [Resolve that I'm stupid] Going out of scope before it should be
This is the start of the chain of call stacks. You can see where Hourglass gets put on the stack and then isn't on it any more *before* AddToCount is called.
5
frmCallStackDemo.cmdStartCounting_Click(Private Sub)
6
frmCallStackDemo.cmdStartCounting_Click(Private Sub)
cHourglass.Hourglass(Public Sub)
7
frmCallStackDemo.cmdStartCounting_Click(Private Sub)
frmCallStackDemo.AddToCount(Private Sub)
Last edited by cafeenman; Apr 5th, 2024 at 02:33 PM.
-
Apr 6th, 2024, 05:13 AM
#7
Re: [Resolved - I'm stupid] Going out of scope before it should be
Once again, it seems that you want to chat, from the subject you have given. Be concise and state the question you want to be resolved and people will want to visit your thread to answer that. A stream of consciousness is not something people necessarily want to dip into.
Also, you don't need to add "Resolved, I'm stupid", just mark it resolved.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Apr 6th, 2024, 10:37 AM
#8
Thread Starter
PowerPoster
Re: [Resolved - I'm stupid] Going out of scope before it should be
Actually I'm just kind of sorry I came back here. Sorry that I'm doing it all wrong for you folks.
-
Apr 7th, 2024, 04:06 AM
#9
Re: [Resolved - I'm stupid] Going out of scope before it should be
It isn't wrong for us, it is wrong for you.
We're not criticising you. You said you wanted responses and we've given you pointers as to how to receive them. It seems you want to 'engage' but you just need to gauge the mood of the forum before posting. This is mostly a technical forum and it is normally a place where we raise and resolve queries. The above pointers on how to do that will work. No need to give up so early.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Apr 7th, 2024, 06:51 AM
#10
Thread Starter
PowerPoster
Re: [Resolved - I'm stupid] Going out of scope before it should be
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|