My addin is crashing with the message "AccessViolationException was unhandled - Attempted to read or write protected memory.
I think that the problem may be that Revit is trying to update the UI during the export (see attached error screenshots).
Is there a way to suspend the screen update?
At the moment the user sees the screen flashing but nothing useful displayed, mostly blank.
The addin is modeless and based on the standard sample. The crash happens at the line highlighted in red below
(also when printing)
Public Sub ExportDWFx(ByVal uiapp As UIApplication)
Try
Dim doc As Autodesk.Revit.DB.Document = uiapp.ActiveUIDocument.Document
Using t As New Transaction(doc, "Export to DWFx")
If t.Start() = TransactionStatus.Started Then
'make sure that a suitable print setup is used
DWFSetup(uiapp)
'NB displaying a progress indicator causes an exception and is best avoided
For n = 0 To Export_Name_List.Count - 1
Dim Export_Viewset As New ViewSet
Export_Viewset.Insert(Export_View_List(n))
Dim Filename As String = Export_Name_List(n)
doc.Export(Export_FolderName, Filename, Export_Viewset, DWFx_Options)
Next
t.Commit()
End If
End Using
Solved! Go to Solution.
Solved by PaulCollins7972. Go to Solution.
Hi Paul,
Is DWFx_Options within scope?
Are you sure you're not mixing dwf with dwfx? They are separate.
Is the document you're exporting from active?
-Matt
Thanks for your responses.
When I had the crash today it was making 10 dwfx files. This time it made the first 6 then crashed.
I get the same error when printing to pdf, printing to an actual printer and exporting to dwg.
But most of the time it is crash free.
The detailed error attached mentions "UI update" but I am not attempting any UI updates (ie not interacting with my form at all) but Revit is trying to update the screen, just like it does if you print a view set through the usual Revit UI.
That is why I am asking if you can suppress the screen updates
Ah. Gotcha.
I don't think you mentioned the screen updates, or the form, though I just noticed 'modeless' in your original post.
Using a modeless dialog for exporting doesn't sound the right way to go about it.
Use a modal form that closes before exporting the files and you'll probably be fine.
Or you could use a progress bar on a modal form, if you set it up right.
I already have a modal version of this addin that works, I am trying to make it modeless as this works much better for the users.
A lot of the other things that it does work fine in the modeless version, such as updating the revision of a batch of drawings
Things like revisions don't use/cause UI regeneration.
It also allows users to align plan viewports on a series of drawings that stack vertically, i.e. floorplans of a tower.
That updates the UI and hasn't crashed
I don't believe that they are the same type of generation. Either way, it doesn't matter - it doesn't solve your issue.
Have you considered using PostCommand?
I have been trying to fix my crashing issue.
Didn't mention that my winform has a WPF usercontrol on it. Looking around I reckon that my issue is probably to do with that as there many other documented cases out there.
As a test I added a regular winform button to my main form and made it run the same code as the WPF button.Click the ordinary button and works ok, click the WPF button and it causes random crashes so for me that sort of proves that the WPF
The issue is similar to this posting I found "this is an access violation on WPF's render thread. Looking at this, we've seen similar crashes that were mainly due to a problem with the video driver. If you are seeing this only on a few machines, this is likely the case here as well"
I found this here : https://social.msdn.microsoft.com/Forums/vstudio/en-US/684b550f-80b4-4fe4-8cd2-b04f58dc50a5/wpf-cont...
I gave up with WPF embedded controls and trying to create a modeless version of my app.
I have reverted to the modal version which seems stable and have created a similar interface using conventional winform controls.
Shame as I wasted a lot of time on that. Maybe I will try again later.
Thanks
Can't find what you're looking for? Ask the community or share your knowledge.