Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory corruption with C# [Csharp] bindings #284

Open
GeneThomas opened this issue Sep 26, 2021 · 7 comments
Open

Memory corruption with C# [Csharp] bindings #284

GeneThomas opened this issue Sep 26, 2021 · 7 comments

Comments

@GeneThomas
Copy link

i. version of lib3mf: 2.2.0
ii. operating system: Windows 10
iii. what did you do:
Compiled and ran the attached project:

class ThreeMfTest
{
    public static void Main()
    {
        CModel model = Wrapper.CreateModel();

        CColorGroup colorGroupTest = model.AddColorGroup();
        sColor redTest = Wrapper.RGBAToColor(255, 0, 0, 255);
        uint idRedTest = colorGroupTest.AddColor(redTest);
        // throws System.AccessViolationException:
        //   HResult = 0x80004003
        //   Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    }
}

iv. expected:
I expected the code to not throw an exception
v.
It throws an exception indicating that memory has probably been corrupted.

I shall attach a full solution .sln etc.. so the fault can be reproduced.

@GeneThomas
Copy link
Author

3MfTest.zip

Attached is zip file containing C# solution to exercise the fault.

When I am finish I shall have some C# examples translated from C++ that you can add to your package.

@GeneThomas
Copy link
Author

GeneThomas commented Sep 26, 2021

lib3MF v2.1.1 and v2.0.0 have the same fault, has the CSharp bindings ever worked?

@rahimshahid
Copy link

rahimshahid commented Apr 25, 2023

Having the exact same problem with version 2.2.0 (and older versions as well e.g. 2.1.1, 2.0.1 & 2.1.0).

Problem does not only occur with adding colors, it also occurs once you add a material e.g.

CModel rootModel= Wrapper.CreateModel();
var baseMatGroup = rootModel.AddBaseMaterialGroup();
var darkBlue = Lib3MF.Wrapper.RGBAToColor(20, 20, 90, 255);
baseMatGroup.AddMaterial("material1", darkBlue); // ---> throws the same exception 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

Any idea how to solve this or any Work Around to get the colors working on C# ?

@CallMeSwal
Copy link

Hey just pinging this thread to see if there is any solution? We are also getting "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." when trying to add color to model with c# bindings (v2.3.2).

@vijaiaeroastro
Copy link
Collaborator

@CallMeSwal We honestly do not even have tests for C Sharp bindings. We will consider this for the 2.4.2 release. We have improved the Python and Golang bindings in the past two releases. We will consider C Sharp binding improvements for the current release.

@CallMeSwal
Copy link

@vijaiaeroastro thanks for the quick reply! Can you confirm if all of the Python bindings are tested for v2.3.2?

@vijaiaeroastro
Copy link
Collaborator

vijaiaeroastro commented Feb 10, 2025

@CallMeSwal Yes. I suggest using 2.3.3, recently released after we found an issue in Mac OS. However, Python bindings are pretty stable, and we have ported almost every example from C++ to Python

https://github.com/3MFConsortium/lib3mf/tree/master/SDK/Examples/Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants