Author Topic: System.AccessViolationException in wcl.dll  (Read 17042 times)

dartecs

  • Guest
System.AccessViolationException in wcl.dll
« on: October 03, 2012, 06:15:45 PM »
My C# application receives about 80 bytes per second from a bluetooth sensor. While receiving those bytes I occasionally get a System.AccessViolationException in wcl.dll.

My wclClient.OnData handler looks like this:

        private void OnDataReceived(object sender, wcl.wclDataEventArgs e)
        {
            lock (mRxBytesLock)
            {
                mRxBytes.AddRange(e.Data);
            }
        }

While receiving data I frequently scan for new devices using a wclBluetoothDiscovery and send data every few seconds:

        private void SendTgm(byte[] tgm)
        {
            try
            {
                lock (mSendLock)
                {
                    if (IsConnected)
                    {
                        wcl.wclErrors.wclShowError(mClient.Write(tgm, (uint)tgm.Length));
                        if (TgmSent != null)
                            TgmSent(new List<byte>(tgm));
                    }
                }
            }
            catch
            {
                Disconnect();
            }
        }


Any idea on what could cause the access violation inside wcl.dll?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: System.AccessViolationException in wcl.dll
« Reply #1 on: October 03, 2012, 07:32:05 PM »
Hello,

Empty tgm array or wrong Length?

dartecs

  • Guest
Re: System.AccessViolationException in wcl.dll
« Reply #2 on: October 04, 2012, 09:12:41 AM »
Empty tgm is very unlikely. But I have now added a check before sending:

        private void SendTgm(byte[] tgm)
        {
            try
            {
                lock (mSendLock)
                {
                    if (IsConnected)
                    {
                        System.Diagnostics.Debug.Assert(tgm.Length > 0);
                        wcl.wclErrors.wclShowError(mClient.Write(tgm, (uint)tgm.Length));
                        if (TgmSent != null)
                            TgmSent(new List<byte>(tgm));
                    }
                }
            }
            catch
            {
                Disconnect();
            }

        }

tgm.Length should always be correct as this is property of the .NET array type.

Now if the tgm should be empty for whatever reason the newly inserted assertion would fire. If the AccessViolationException should throw again without the assertion being fired before I will get back to you again.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: System.AccessViolationException in wcl.dll
« Reply #3 on: October 04, 2012, 10:21:25 AM »
OK, thanks.  I am checking this too.

dartecs

  • Guest
Re: System.AccessViolationException in wcl.dll
« Reply #4 on: October 04, 2012, 02:04:47 PM »
Maybe this problem could also be related to Toshiba stack? (see my other post http://forum.btframework.com/index.php/topic,1692.0.html)

I am now testing without Toshiba Stack and will see if this problem disappeared.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: System.AccessViolationException in wcl.dll
« Reply #5 on: October 04, 2012, 02:30:38 PM »
Yearly I faced AV with Toshiba but this problem has been fixed (at least I haven't been noticed about that since fixed).

 

Sitemap 1 2 3 4 5 6 7