System.AccessViolationException Attempted to read or write protected memory
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the crash with Program.cs and the PclIoLib configuration, then trace the reported path through CppSharp.ConsoleDriver.Run, Driver.ParseCode, and ClangParser.ParseHeader. Check the supplied pcl/io/pcd_io.h, pcl/memory.h, and pcl/type_traits.h inputs and their include and library directories. Done means parsing completes without AccessViolationException and generated bindings are produced.
Written by the indexing model from the issue text.
Description
Brief Description
I want to generate csharp bindings for pcl-1.14.0 .
follow the doc:
dotnet add package CppSharp --version 1.1.5.3168
internal class PclIoLib : ILibrary
{
private string _includeDir;
private string _libDir;
private string _outputDir;
public PclIoLib(string includeDir, string libDir, string outputDir)
{
_includeDir = includeDir;
_libDir = libDir;
_outputDir = outputDir;
}
public void Setup(Driver driver)
{
var pclRoot = Environment.GetEnvironmentVariable("PCL_ROOT");
var boostIncludeRoot = Path.Combine(pclRoot!, "3rdParty", "Boost", "include", "boost-1_84");
var options = driver.Options;
options.GeneratorKind = GeneratorKind.CSharp;
var module = options.AddModule("pcl_io");
module.IncludeDirs.Add(_includeDir);
module.IncludeDirs.Add(boostIncludeRoot);
module.Headers.Add(@"pcl\io\pcd_io.h");
module.Headers.Add(@"pcl\memory.h");
module.Headers.Add(@"pcl\type_traits.h");
module.LibraryDirs.Add(_libDir);
module.Libraries.Add("pcl_io.lib");
driver.Options.OutputDir = _outputDir;
}
public void SetupPasses(Driver driver)
{
driver.Context.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any);
driver.Context.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass());
}
public void Preprocess(Driver driver, ASTContext ctx)
{
}
public void Postprocess(Driver driver, ASTContext ctx)
{
}
}
And Program.cs as:
var pclRoot = Environment.GetEnvironmentVariable("PCL_ROOT");
var includeRoot = Path.Combine(pclRoot!, "include", "pcl-1.14");
var libRoot = Path.Combine(pclRoot!, "lib");
var outputDir = "C:\\Users\\perso\\source\\desktop-apps\\Pcl.Net\\src";
Console.WriteLine($"{nameof(pclRoot)}:{pclRoot}");
Console.WriteLine($"{nameof(includeRoot)}:{includeRoot}");
Console.WriteLine($"{nameof(libRoot)}:{libRoot}");
ConsoleDriver.Run(new PclIoLib(includeRoot, libRoot, outputDir));
Console.WriteLine("Ok, It's done!");
run and output:
pclRoot:C:\Program Files\PCL 1.14.0
includeRoot:C:\Program Files\PCL 1.14.0\include\pcl-1.14
libRoot:C:\Program Files\PCL 1.14.0\lib
Parsing libraries...
Parsed 'pcl_io.lib'
Parsing code...
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at CppSharp.Parser.ClangParser+__Internal.ParseHeader(IntPtr)
--------------------------------
at CppSharp.Parser.ClangParser.ParseHeader(CppSharp.Parser.CppParserOptions)
at CppSharp.ClangParser.ParseSourceFiles(System.Collections.Generic.IEnumerable`1<System.String>, CppSharp.Parser.ParserOptions)
at CppSharp.Driver.ParseCode()
at CppSharp.ConsoleDriver.Run(CppSharp.ILibrary)
at Program.<Main>$(System.String[])
How can I fix this?
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
OS: Windows
IDE: VS2022
Used headers
Used settings
Target: MSVC
Stack trace or incompilable generated code
- Dominant language
- C#
- Stars
- 3.4k
- Forks
- 541
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mono/CppSharp
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
How to get started Open
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100