CppSharp icon indicating copy to clipboard operation
CppSharp copied to clipboard

NullReferenceException at VisitTypedefNameDecl

Open emepetres opened this issue 3 years ago • 4 comments

Brief Description

I'm trying to create a wrapper for MuJoCo for c# in Linux. I've downloaded the library and its include files, and followed the Getting Started doc to create the setup below. I'm getting a NullReferenceException without any information about the offending source header code or how to solve it. Full code to reproduce the issue at https://github.com/emepetres/MuJoCoSharp

Setup:

            var includeFiles = Directory.GetFiles(@"[LIBPATH]/include");

            var options = driver.Options;
            options.Verbose = true;
            options.GeneratorKind = GeneratorKind.CSharp;
            var module = options.AddModule("MuJoCo");

            module.IncludeDirs.Add(@"[LIBPATH]/include");
            module.Headers.AddRange(includeFiles);

            module.LibraryDirs.Add(@"[LIBPATH]/bin");
            module.Libraries.Add("libmujoco210.so");

Linux (Manjaro, dotnet 5.0, CppSharp v1.0.0)

Used headers

MuJoCo include files at https://github.com/deepmind/mujoco/tree/main/include

Target: C#

Stack trace or incompilable generated code
Parsing libraries...
Parsed 'libmujoco210.so'
Parsing code...
Unhandled type class 'Complex'
Parsed '/home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjrender.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/glfw3.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjui.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjvisualize.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/uitools.c, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mujoco.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjdata.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjxmacro.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/uitools.h, /home/jcarnero/source/MuJoCoSharp/build/mujoco210/include/mjmodel.h'
Processing code...
Pass 'CppSharp.Passes.ResolveIncompleteDeclsPass'
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at CppSharp.AST.AstVisitor.VisitTypedefNameDecl(TypedefNameDecl typedef)
   at CppSharp.AST.AstVisitor.VisitTypedefDecl(TypedefDecl typedef)
   at CppSharp.AST.TypedefDecl.Visit[T](IDeclVisitor`1 visitor)
   at CppSharp.AST.AstVisitor.VisitDeclarationContext(DeclarationContext context)
   at CppSharp.Passes.TranslationUnitPass.VisitTranslationUnit(TranslationUnit unit)
   at CppSharp.Passes.TranslationUnitPass.VisitASTContext(ASTContext context)
   at CppSharp.Passes.ResolveIncompleteDeclsPass.VisitASTContext(ASTContext c)
   at CppSharp.Generators.BindingContext.<RunPasses>b__37_0(TranslationUnitPass pass)
   at CppSharp.PassBuilder`1.RunPasses(Action`1 action)
   at CppSharp.Generators.BindingContext.RunPasses()
   at CppSharp.Driver.ProcessCode()
   at CppSharp.ConsoleDriver.Run(ILibrary library)
   at BindingGenerator.Program.Main(String[] args) in /home/jcarnero/source/MuJoCoSharp/src/BindingGenerator/Program.cs:line 12

emepetres avatar Nov 17 '21 21:11 emepetres

@emepetres thank you for your report, we'll check whenever possible. If you need a quick resolution, please contact our support.

ddobrev avatar Nov 17 '21 21:11 ddobrev

@emepetres your other option is to try fixing it yourself while we guide you.

ddobrev avatar Nov 28 '21 15:11 ddobrev

Sure, working on it I'm getting now a different error: Sequence contains no matching element, but I think the main problem is that there is no much error handling and therefore when an error occurs, there is no feedback at all about the source code that throw the failure. That makes debugging hard :)

emepetres avatar Nov 28 '21 21:11 emepetres

To begin with, have you been able to isolate a test case? We can import it in the tests so that we're safe against regressing it.

ddobrev avatar Nov 29 '21 09:11 ddobrev