Page 1 of 1

System.AccessViolationException(s) with Smart Labels

Posted: Mon May 17, 2021 4:49 pm
by aarond
I have uncovered a couple places where I get System.AccessViolationException that seem to be related to Smart Labels.

First, setting the model path and turning on Smart Labels repeatedly will cause an exception after 3-5 repetitions. I was able to reproduce this in the Smart Labels sample using the Cow.mdg model.
1) Open model in Smart Labels sample (I used Cow.mdg)
2) Select Labels -> Auto Generate
3) Repeat until crash

System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=mscorlib
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at KernCADnet._DKernCADnet.set_ModelPath(String )
at AxKernCADnet.AxKernCADnet.set_ModelPath(String value)
at SmartLabels.SmartLabelsForm.OnFileOpen(Object sender, EventArgs e) in C:\Projects\DGKernel_6_2\Samples\NET\C#\Labels\SmartLabels\SmartLabelsForm.cs:line 97

=====================================================

Second, using two instances of AxKernCADnet will cause a crash after enabling Smart Labels on both of them then calling UpdateView() on both of them.

I use two AxKernCADnet instances, one to display the front of the model and one for the back

Code: Select all

axKernCADnetFront.ModelPath = modelPath;
axKernCADnetBack.ModelPath = modelPath;
Then create labels on them like so

Code: Select all

	CreateLabelsHelper(axKernCADnetFront.GetView() as IView_DG);
	CreateLabelsHelper(axKernCADnetBack.GetView() as IView_DG);

        private void CreateLabelsHelper(IView_DG view)
        {
            if (view != null)
            {
                ISmartLabelManager_KC labelManager = (ISmartLabelManager_KC)view;
                IDynamicScreenItemManager_KC dynamicManager = (IDynamicScreenItemManager_KC)view;
                dynamicManager.Enable(true);
                labelManager.SetStringSource(EStringSource.eStringSourceLayerName);
                labelManager.CreateLabelsAutomatic();
            }
        }
And then calling UpdateView() throws an exception on the second instance

Code: Select all

axKernCADnetFront.UpdateView();
axKernCADnetBack.UpdateView();	// <- crash here
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=mscorlib
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at KernCADnet._DKernCADnet.UpdateView()
at AxKernCADnet.AxKernCADnet.UpdateView()

Re: System.AccessViolationException(s) with Smart Labels

Posted: Tue May 18, 2021 4:58 am
by nickz
Thank you for reporting, Aaron
We are digging
Regards

Re: System.AccessViolationException(s) with Smart Labels

Posted: Thu May 27, 2021 9:04 am
by nickz
Hi Aaron
We have fixed this. Please get today's 5214 update:

Notice, if you are upgrading from v5.2 there was a change: The smart labels management needs to be enabled after setup, like:

Code: Select all

   IDynamicScreenItemManager_KC iDynamicManager = (IDynamicScreenItemManager_KC)iView;
   iDynamicManager.Enable(true);
The IDynamicScreenItemManager_KC can be queried from ISmartLabelManager_KC as well.

Please do not hesitate posting any issues
Regards

Re: System.AccessViolationException(s) with Smart Labels

Posted: Thu Jun 10, 2021 7:14 pm
by aarond
Thank you Nick, this no longer crashes but I am getting an odd behavior where the labels are shown twice on each section if I enable them on two views. If I enable them on only the left or right view there is no issue but when enabling them on both views they get duplicated.

The code is the same as shown in the first post.
Screenshot 2021-06-10 121219.png
Screenshot 2021-06-10 121219.png (151.36 KiB) Viewed 18513 times

Re: System.AccessViolationException(s) with Smart Labels

Posted: Mon Jun 14, 2021 12:04 am
by nickz
Yeah, this is weird
v5 was based on DirectX 9.1 where text was rendered practically in immediate mode. In DX11 it was changed to use hardware acceleration. So implementation has changed significantly. This is where the bug came from.
We are working on it....
Thank you for reporting

Re: System.AccessViolationException(s) with Smart Labels

Posted: Wed Jun 16, 2021 4:54 am
by nickz
Fixed in 5217 update. There was a quirk in renderer
Regards