4
votes

I have a legacy vb6 app that crashes on exit - both as an executable and in the IDE. How can I avoid the crash?

  • I am currently unloading the forms (except the frmmain) in form_unload, releasing all the ADODB RecordSets, setting all the boundcollections = nothing.
  • I have attempted to SetErrorMode SEM_NOGPFAULTERRORBOX in the form_terminate event and that has not stopped the error from occurring.
  • I have also checked for subclasses being instantiated in my code and found none.
  • I have checked into the components from outside Microsoft that are used - they are the ComponentOne flexgrid 8 spelling 8 and ComponentOne sizer control. An extensive web and forum search has not turned up any known problems similar to mine for these controls.

The issue does not seem to occur if I shut down the program before actually doing anything. However loading the bound controls seems to be near where the problem is rooted, in spite of repeatedly stepping with the debugger it seems that the start of the problem "moves around". The problem occurs with the programmatic exit, the "X" and the IDE "end" control The error message is The instruction at "0x77d042b8" referenced memory at "0x055c9028". The memory could not be "Read". The title in the error box is a tool tip (differing at different times) from inside my app I have put breaks when stepping through the code - the app crashes on the exit sub line at the Form_Unload event

ADDED
I realized that I should have included some other information with my original post. I was very tired and frustrated when I made it and sorry it was so difficult to read.
Now
1) I do have the latest service pack (6) installed, and the latest builds of the components
2) doing a debug in my VS2010 ide (which is on the same server) I got a very long stack dump beginning with OLEAUT32.dll, I updated that DLL but found no change
3) I am actually running (and working on) the program through a remote desktop connection. The program crashes on my desktop as well as on the users terminal server connections.
4) The OS I am running under is Windows Server 2003
5) the code I am running is
'code'

    Private Sub Form_Unload(Cancel As Integer)
        Set rsChild = Nothing
        Set rsCaseFile = Nothing
        ' many similar record sets closing
        ys.CloseConnection
        Set ys = Nothing
        UnloadAllForms (Me.Name)
        ' closeing bound collections 
        Set bndChild = Nothing
         Set bndAuth = Nothing
         ' more bound collections closed
         ' i had added the next two lines but it made no difference
         frmmain.close
         Set frmMain = nothing 
         getout
    end sub
    Public Sub UnloadAllForms(Optional FormToIgnore As String = "")
        Dim f As Form
        For Each f In Forms
            If Not f Is Nothing Then
                If f.Name <> FormToIgnore Then
                    Unload f
                    Set f = Nothing
                End If
            End If
        Next f   
    End Sub

'\code'  

6) I have added a "getout" routine in the start up module on the hope that will allow the form object to close cleanly this did not fix the issue
Thank you all so much for your help

3
Can you post the code you are running when you shut down?jac
wow that is a lot of dense text in one paragraph for a person to read and comprehend for free ... some effort in formatting the text to be readable might be in orderuser177800
@p.campbell the issue is right there in the first sentence "my vb6 app crashes on exit - both as an executable and in the IDE." It means "how can I avoid the crash"! @Jarrod It is a well phrased question, just in need of some formatting. I will edit it. In future it might be friendlier to a noobie if you edited it yourself?? @Close voters and downvoters. No offence, but what is wrong with you? This is a clear question. It's long but that's because IronHead has done good work researching the problem. It's not "too localized". +1 to the question and I shall vote to reopen if it is closed.MarkJ
@p.campbell OK, just for you, I will edit the question again and add "How can I avoid the crash?". If you really need to be told that he doesn't want his program to crash. IronHead can't post the code because he has a large program and he doesn't know which part is causing the crash. It's not necessarily code that runs when the program exits, it's very likely that some memory corruption/bad pointers earlier that only surfaces on exit. I promise you, this is a good question. FWIW I have some VB6 stats around hereMarkJ

3 Answers

5
votes

It appears that the bug is dead, the kill was in 10 parts
1) very carefully disposing of all objects
2) confirming that each recordset was closed before it was set to nothing
3) closing each form from the last forms close event
4) set the last form .visible = false then called a timer for 1 second
5) added a getout call to the bottom of the last forms unload event
6) put the getout in a module
7) added

'code'
Private Declare Function SetErrorMode Lib "kernel32" ( _
   ByVal wMode As Long) As Long  
Private Const SEM_FAILCRITICALERRORS = &H1  
Private Const SEM_NOGPFAULTERRORBOX = &H2  
Private Const SEM_NOOPENFILEERRORBOX = &H8000&  
'code'  

to the declarations in that module
8) called that declaration with

'code'
SetErrorMode SEM_NOGPFAULTERRORBOX  
'code' 

at the start of the getout sub
9) confirmed that the last open form was closed
10) included this code at the bottom of the getout sub to make sure it could close

'code'  
    Dim tstart As Date  
    tstart = TimeValue(Now())  
    Dim i As Integer  
    i = 0  
    Do While (DateAdd("s", 3, tstart)) > TimeValue(Now())  
        For i = 0 To 1000  
            i = i + 1  
        Next  
        i = 0  
    Loop   
   ' endtask("PLacements") 

    End  
'code'  

that last part was sorta the equivalent of driving wooden stake into its heart
thank you all for the help you have given me and specially MarkJ for editing my original submission to forum standards - I'll try and pay it back when I can

0
votes

What is happening is there is some background work going on. Most likely some process fired off asynch code that is being handled by an event handler AFTER a close() has been issued. The avoid method would be to hide the form and then wait for a bit before finishing the close method. To fix it, you have to determine what is firing off work on a background thread. In classic VB, this can end up being painful.

0
votes

A nasty situation.

  • Are you on the latest Windows service packs, VB SP6 and the latest builds of the components?
  • Does the problem happen on other machines or is it just your machine? If it's just your machine - buy another machine.
  • Try to track this down by taking pieces of the program away until it stops crashing. Then put pieces back in until it does crash. This should help you track down which components or code are involved. It doesn't matter whether the program works, you just need to know whether it crashes on exit. You can comment out or delete whole classes, delete controls, anything.