Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crash - Attempted to read or write protected memory.

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
PaulCollins7972
4391 Views, 10 Replies

Crash - Attempted to read or write protected memory.

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

10 REPLIES 10
Message 2 of 11

It happen to me when I i tried to Async and await for the sake of Progress bar... but I realized Revit is not Thread Safe. so I used MVVM pattern to resolve that.are you running your code on a different Thread? can you Illustrate more.
Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 11

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 4 of 11

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

Message 5 of 11

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.

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 6 of 11

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

Message 7 of 11

Things like revisions don't use/cause UI regeneration.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 8 of 11

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

Message 9 of 11

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?


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 10 of 11

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...

Message 11 of 11

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.

Post to forums  

Autodesk Design & Make Report