Author Topic: Access violation when closing application  (Read 6449 times)

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Access violation when closing application
« on: July 08, 2013, 04:52:38 PM »
Hello,


We are using version 6.12.0.0 of wcl Lite .net. 

We allways get the access violation when closing the application.

First time we got the exception was after we have updated the wcl library from 6.10.8.0 to 6.11.9.0.

Here is the exception:


System.AccessViolationException wurde nicht behandelt.
  Message=Es wurde versucht, im gesch

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Access violation when closing application
« Reply #1 on: July 08, 2013, 04:58:10 PM »
Hello,

Do you call wclAPI.Unload before closing the app?

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #2 on: July 08, 2013, 05:24:20 PM »

Hi,

where is the rest of my post?

Yes I do call wclAPI.Unload before closing and I have written this in my Post an much more but it ist not there.  :(

Regards,
Roland

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #3 on: July 08, 2013, 05:31:22 PM »

Her is what I have sent:


We call load here:


        Public Sub Starten()

            Me.obj_wcl_api = New wcl.wclAPI
            Me.obj_bt_radios = New class_bt_radios(Me)

            Me.obj_wcl_api.Load()

            Debug.WriteLine("wcl load " & New StackTrace().ToString)

        End Sub

Calling stack at this moment:

wcl load    bei DH.Schnittstellen.BT.class_bt.Starten()
   bei DH.Schnittstellen.BT.class_bi_bt_1.Start()
   bei DH.Schnittstellen.class_items.Start()
   bei DH.frm_main.me_Load(Object sender, EventArgs e)
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei System.Windows.Forms.Form.OnLoad(EventArgs e)
   bei System.Windows.Forms.Form.OnCreateControl()
   bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   bei System.Windows.Forms.Control.CreateControl()
   bei System.Windows.Forms.Control.WmShowWindow(Message& m)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei System.Windows.Forms.Form.WmShowWindow(Message& m)
   bei System.Windows.Forms.Form.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
   bei System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   bei System.Windows.Forms.Control.set_Visible(Boolean value)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   bei SW_SCS.My.MyApplication.Main(String[] Args)
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()


And unload here:

        Public Sub Beenden()

            Me.obj_wcl_api.Unload()

            Debug.WriteLine("wcl unload " & New StackTrace().ToString)

        End Sub


Calling stack at this moment:

wcl unload    bei DH.Schnittstellen.BT.class_bt.Beenden()
   bei DH.Schnittstellen.BT.class_bi_bt_1.Shutdown()
   bei DH.Schnittstellen.class_items.Shutdown()
   bei SW_SCS.My.MyApplication.MyApplication_Shutdown(Object sender, EventArgs e)
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnShutdown()
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   bei SW_SCS.My.MyApplication.Main(String[] Args)
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()


Do you have any idea?


Roland






Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #4 on: July 08, 2013, 05:34:02 PM »
Sorry, now I lost the exception:

System.AccessViolationException wurde nicht behandelt.
  Message=Es wurde versucht, im gesch

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Access violation when closing application
« Reply #5 on: July 08, 2013, 05:35:14 PM »
Hi,

We have never been reported about A/V on closing app except case when wclAPI was not unloaded.

Possible reason you are using some objects which have already been destroyed (what is class_bt_radio, what it does? I do not see that is is released somewere). Would be great if you can send us your project for futher checking to mike@btframework.com.

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #6 on: July 08, 2013, 05:37:04 PM »
Oh, it was the german

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #7 on: July 08, 2013, 05:41:09 PM »

It is working in the preview, but if I post teh message, everything is away after th german character (I can't write it, because the message would be corrupted again).

Here is once again the acception:

System.AccessViolationException wurde nicht behandelt.
  Source=wcl
  StackTrace:
       bei EnterCriticalSection(_RTL_CRITICAL_SECTION* )
       bei wcl.wcl_int.CwclSync.Enter(CwclSync* )
       bei wcl.wcl_int.wclUnregisterWnd(HWND__* hWnd)
       bei wcl.wcl_int.CwclBaseComponent.DeallocateWindow(CwclBaseComponent* )
       bei wcl.wcl_int.CwclBluetoothDiscovery.Terminate(CwclBluetoothDiscovery* )
       bei wcl.wcl_int.CwclBluetoothDiscovery.{dtor}(CwclBluetoothDiscovery* )
       bei wcl.wcl_int.CwclBluetoothDiscovery.__vecDelDtor(CwclBluetoothDiscovery* , UInt32 )
       bei wcl.wclBluetoothDiscovery.!wclBluetoothDiscovery()
       bei wcl.wclBluetoothDiscovery.Dispose(Boolean )
       bei System.ComponentModel.Component.Finalize()
  InnerException:

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #8 on: July 08, 2013, 05:54:16 PM »

I can't send the whole project, because it is very big.


her are some more peaces of the project:

Code: [Select]

        Private Sub obj_wcl_api_AfterLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles obj_wcl_api.AfterLoad

            Me.obj_bt_radios.Suchen()

        End Sub


         Public Sub Suchen()

            Dim int_fehler As Integer

            ' WCL-Bluetooth-Objekte
            Dim obj_wcl_bluetooth_discovery As wcl.wclBluetoothDiscovery = New wcl.wclBluetoothDiscovery
            Dim obj_wcl_bluetooth_radios As wcl.wclBluetoothRadios = New wcl.wclBluetoothRadios

            ' Nach aktuellen Radios suchen
            int_fehler = obj_wcl_bluetooth_discovery.EnumRadios(obj_wcl_bluetooth_radios)

            ' Ueberpruefung, ob welche hinzugekommen oder entfernt wurden
            If obj_wcl_bluetooth_radios.Count = 0 Then

                If Me.dict_radios.Count = 0 Then

                    ' Noch keine Radios gefunden -> Keine Aenderung

                Else

                    ' Alle vorher bekannten Radios wurden entfernt -> Radios nicht mehr Verfuegbar
                    For Each obj_radio As class_bt_radio In Me.dict_radios.Values

                        ' Pruefen, ob Radio vorher Verfuegbar war
                        If obj_radio.Verfuegbar Then

                            ' Radio-Geraet abmelden
                            obj_radio.Verfuegbar = False
                            obj_radio.Geaendert = Now
                            RaiseEvent RadioAbgemeldet(Me, New RadioAbgemeldet_EventArgs(obj_radio))

                        End If

                    Next

                End If

            Else

                ' Pruefen, ob ein neues Geraet hinzugefuegt wurde
                For int_index As UInteger = 0 To CUInt(obj_wcl_bluetooth_radios.Count - 1)

                    ' Radio-Adresse ermitteln
                    Dim str_adresse As String = ""
                    int_fehler = obj_wcl_bluetooth_radios.Item(int_index).GetAddress(str_adresse)

                    ' Nur Auswerten, wenn Adresse gelesen werden konnte
                    If int_fehler = 0 Then

                        Dim str_name As String = ""

                        ' Ist die Radio-Adresse bekannt?
                        If Me.dict_radios.ContainsKey(str_adresse) Then

                            ' Pruefungen, ob sich Geraete-Parameter geaendert haben
                            Dim bol_radio_parameter_geaendert As Boolean = False
                            Dim bol_geraete_suche_starten As Boolean = False

                            ' Namen auslesen
                            If int_fehler = 0 Then
                                int_fehler = obj_wcl_bluetooth_radios.Item(int_index).GetName(str_name)
                                If int_fehler = 0 Then
                                    If Me.dict_radios.Item(str_adresse).Name <> str_name Then
                                        bol_radio_parameter_geaendert = True
                                        Me.dict_radios.Item(str_adresse).Name = str_name
                                    End If
                                End If
                            End If

                            ' Pruefen, ob Radio vorher Verfuegbar war
                            If Not Me.dict_radios.Item(str_adresse).Verfuegbar Then
                                Me.dict_radios.Item(str_adresse).Verfuegbar = True
                                bol_radio_parameter_geaendert = True
                                bol_geraete_suche_starten = True
                            End If

                            ' Radio-Geraet wieder anmelden
                            If bol_radio_parameter_geaendert Then
                                Me.dict_radios.Item(str_adresse).Geaendert = Now
                                RaiseEvent RadioAngemeldet(Me, New RadioAngemeldet_EventArgs(Me.dict_radios.Item(str_adresse)))
                            End If

                            ' Nach Geraete des Radios suchen
                            If bol_geraete_suche_starten Then
                                Me.dict_radios.Item(str_adresse).Geraete.Suche_Starten()
                            End If

                        Else

                            ' Radio-Adresse ist unbekannt -> Radio der Liste hinzufuegen
                            Dim obj_bt_radio As class_bt_radio = New class_bt_radio(Me, obj_wcl_bluetooth_radios.Item(int_index))

                            ' Namen auslesen
                            If int_fehler = 0 Then
                                int_fehler = obj_wcl_bluetooth_radios.Item(int_index).GetName(str_name)
                            End If

                            ' Radio-Parameter setzen, wenn Name gelesen werden konnte
                            If int_fehler = 0 Then

                                obj_bt_radio.Name = str_name
                                obj_bt_radio.Adresse = str_adresse
                                obj_bt_radio.Geaendert = Now
                                obj_bt_radio.Verfuegbar = True
                                '   obj_bt_radio.WCL_Radio.API = obj_wcl_bluetooth_radios.Item(int_index).API

                                AddHandler obj_bt_radio.RadioAktivGeaendert, AddressOf dict_radios_RadioAktivGeaendert
                                AddHandler obj_bt_radio.GeraeteSucheGestartet, AddressOf dict_radios_GeraeteSucheGestartet
                                AddHandler obj_bt_radio.GeraeteSucheBeendet, AddressOf dict_radios_GeraeteSucheBeendet
                                AddHandler obj_bt_radio.GeraetAngemeldet, AddressOf dict_radios_GeraetAngemeldet
                                AddHandler obj_bt_radio.GeraetAbgemeldet, AddressOf dict_radios_GeraetAbgemeldet

                                ' Radio in Liste hinzufuegen
                                Me.dict_radios.Add(str_adresse, obj_bt_radio)

                                ' Neues Radio-Geraet gefunden
                                RaiseEvent RadioAngemeldet(Me, New RadioAngemeldet_EventArgs(obj_bt_radio))

                                ' Nach Geraete des Radios suchen
                                obj_bt_radio.Geraete.Suche_Starten()

                            End If

                        End If

                    End If

                Next

                ' Pruefen, ob ein bekanntes Geraet entfernt wurde
                For Each obj_radio As class_bt_radio In Me.dict_radios.Values

                    Dim bol_geraet_vorhanden As Boolean = False

                    For int_index As UInteger = 0 To CUInt(obj_wcl_bluetooth_radios.Count - 1)

                        ' Radio-Adresse ermitteln
                        Dim str_adresse As String = ""
                        int_fehler = obj_wcl_bluetooth_radios.Item(int_index).GetAddress(str_adresse)

                        ' Nur Auswerten, wenn Adresse gelesen werden konnte
                        If int_fehler = 0 Then

                            ' Pruefen, ob Adresse auch in neuer Liste vorhanden
                            If str_adresse.Equals(obj_radio.Adresse) Then
                                bol_geraet_vorhanden = True
                            End If

                        End If

                    Next

                    ' Wenn Geraet nicht gefunden, dann wurde es entfernt.
                    If Not bol_geraet_vorhanden Then
                        If obj_radio.Verfuegbar Then

                            ' Radio-Geraet abmelden
                            obj_radio.Verfuegbar = False
                            obj_radio.Geaendert = Now
                            RaiseEvent RadioAbgemeldet(Me, New RadioAbgemeldet_EventArgs(obj_radio))

                        End If
                    End If

                Next

            End If

        End Sub



Regards,
Roland

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Access violation when closing application
« Reply #9 on: July 08, 2013, 07:22:14 PM »
OK, i'll check what can be wrong there. May be you can send us your exe file?

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #10 on: July 09, 2013, 08:49:10 AM »
Hello,

I've atached the whole package with dlls.

I am also triing to make a smaller example.

Thanks for your help
Roland
« Last Edit: July 09, 2013, 08:52:31 AM by Mike Petrichenko »

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Access violation when closing application
« Reply #11 on: July 09, 2013, 08:53:10 AM »
Thank you. I have downloaded it and am going to check. I removed attachment from your post so it can't be dowloaded by anyone else.

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #12 on: July 09, 2013, 08:54:02 AM »
Perfect, thank you!

Roland

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Access violation when closing application
« Reply #13 on: July 09, 2013, 07:52:33 PM »
How/when do you call this method:

Public Sub Beenden()

            Me.obj_wcl_api.Unload()

            Debug.WriteLine("wcl unload " & New StackTrace().ToString)

        End Sub

Move wclAPI loading and unloading from those methods (Starten and Beenden) to main form Load/Unload events.

It looks like your application closes, it unloads all DLLs (so static objects are destroyed), than .NET garbage collector starts working and disposes your class which calls wclAPI.Unload what cause call to wclBluetoothDiscovery.Terminate. But static objects are already destroyed and A/V raises.

That's why we always ask to place wclAPI.Load in main form Load and wclAPI.Unload in main form Unload events.

Offline r.cassebohm

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Access violation when closing application
« Reply #14 on: July 10, 2013, 11:32:07 AM »
Hi,

you are right, "Beenden()" was called in MyApplication_Shutdown.

But there seems not do be a Event called "unload" of the main formular. I tried it in Me.FormClosing now, but with the same result.

...

Now I've found the Problem. I have seen, that at multible places in the code new instances of the class wcl.wclBluetoothDiscovery was made.

I have changed it that there is only one instance in the whole code, which is used at multible places. Now I dont get the exception any more.


Many thanks for your help!

Best regards,
Roland


 

Sitemap 1 2 3 4 5 6 7 8 9