Skip to content

Commit 9ab3175

Browse files
authored
Merge pull request #5675 from bclothier/MinorBugFixes
Potentially fix the AV when initial parse occurs too soon.
2 parents 8d2f4de + 9cfe8c5 commit 9ab3175

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

Rubberduck.Parsing/ComReflection/XmlComProjectSerializer.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ public class XmlComProjectSerializer : IComProjectSerializationProvider
1717
public readonly string DefaultSerializationPath;
1818
private readonly IFileSystem _fileSystem;
1919

20-
public XmlComProjectSerializer(
21-
IPersistencePathProvider pathProvider,
22-
IFileSystem fileSystem)
20+
private XmlComProjectSerializer(IFileSystem fileSystem, string defaultPath, string path)
2321
{
24-
DefaultSerializationPath = pathProvider.DataFolderPath("Declarations");
2522
_fileSystem = fileSystem;
26-
}
27-
28-
public XmlComProjectSerializer(IFileSystem filesystem, string path = null)
29-
{
23+
DefaultSerializationPath = defaultPath;
3024
Target = path ?? DefaultSerializationPath;
31-
_fileSystem = filesystem;
3225
}
3326

27+
public XmlComProjectSerializer(
28+
IPersistencePathProvider pathProvider,
29+
IFileSystem fileSystem)
30+
: this(fileSystem, pathProvider.DataFolderPath("Declarations"), null)
31+
{ }
32+
33+
public XmlComProjectSerializer(IFileSystem fileSystem, string path)
34+
: this(fileSystem, path, path)
35+
{ }
36+
3437
private static readonly XmlReaderSettings ReaderSettings = new XmlReaderSettings
3538
{
3639
CheckCharacters = false

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibVBEExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Runtime.InteropServices.ComTypes;
7+
using NLog;
78
using Rubberduck.VBEditor.ComManagement.TypeLibs.Abstract;
89
using Rubberduck.VBEditor.ComManagement.TypeLibs.Unmanaged;
910

@@ -66,6 +67,7 @@ internal class TypeLibVBEExtensions : ITypeLibVBEExtensions
6667
{
6768
private readonly string _name;
6869
private readonly IVBEProject _target_IVBEProject;
70+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
6971

7072
public ITypeLibReferenceCollection VBEReferences { get; }
7173

@@ -87,6 +89,24 @@ public bool CompileProject()
8789
{
8890
try
8991
{
92+
// Prevent a potential access violation by first calling the Placeholder3().
93+
// Under certain conditions where the VBA project is fully compiled, clicking parse
94+
// as soon as Rubberduck has loaded into VBIDE can cause an access violation when
95+
// accessing CompileProject(). We've tried using ComMessagePumper and
96+
// UiDispatcher.FlushMessageQueue but neither helped in preventing the
97+
// access violation. We at least know that Placeholder3() does not save the unsaved
98+
// change so hopefully there should be no permanent side effects from invoking the
99+
// Placeholder3().
100+
try
101+
{
102+
_target_IVBEProject.Placeholder3();
103+
}
104+
catch(Exception ex)
105+
{
106+
Logger.Info(ex, $"Cannot compile the VBA project '{_name}' because there may be a potential access violation.");
107+
return false;
108+
}
109+
90110
_target_IVBEProject.CompileProject();
91111
return true;
92112
}

RubberduckBaseProject.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@
4848
<PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
4949
<DebugType>full</DebugType>
5050
<Optimize>false</Optimize>
51-
<DefineConstants>DEBUG;TRACE</DefineConstants>
51+
<!-- Valid Constants used in the solution:
52+
LOG_COM_RELEASE // Records COM objects released when a safe COM wrapper has been disposed
53+
PRETTY_XML // Includes whitespace and formatting to serialized XML files for XmlComProjectSerializer
54+
REF_COUNT // Tracks the reported reference counts when acquiring/disposing COM objects
55+
THRISTY_DUCK // Outputs the message content from the message pump in VBENativeServices / SubclassingWindow
56+
THRISTY_DUCK_EVT // Outptus the events raised from the message pump in VBENativeServices / SubclassingWindow
57+
TRACE_COM_SAFE // Tracks the COM wrappers added & removed to the ComSafe and also allow serializing the contents of ComSafe
58+
TRACE_TYPEAPI // Tracks the methods called on the wrapped ITypeLib & ITypeInfo
59+
TRACE_COM_POINTERS // Tracks the ComPointer access & disposal
60+
TRACE_MARSHAL // Tracks the calls made through the RdMarshal class (useful for tracking all Marshal methods)
61+
-->
62+
<DefineConstants>DEBUG;TRACE;</DefineConstants>
5263
</PropertyGroup>
5364

5465
<PropertyGroup Condition=" '$(Configuration)' == 'Release'">

0 commit comments

Comments
 (0)