Wireless Communication Library Support Forum

Frameworks => Bluetooth Framework => Topic started by: dartecs on October 03, 2012, 06:15:45 PM

Title: System.AccessViolationException in wcl.dll
Post by: dartecs 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?
Title: Re: System.AccessViolationException in wcl.dll
Post by: Mike Petrichenko on October 03, 2012, 07:32:05 PM
Hello,

Empty tgm array or wrong Length?
Title: Re: System.AccessViolationException in wcl.dll
Post by: dartecs 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.
Title: Re: System.AccessViolationException in wcl.dll
Post by: Mike Petrichenko on October 04, 2012, 10:21:25 AM
OK, thanks.  I am checking this too.
Title: Re: System.AccessViolationException in wcl.dll
Post by: dartecs 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.
Title: Re: System.AccessViolationException in wcl.dll
Post by: Mike Petrichenko 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).