This forum has been archived. All content is frozen. Please use KDE Discuss instead.

AccessViolationException for SparseMatrix

Tags: None
(comma "," separated)
jctaft
Registered Member
Posts
2
Karma
0
Hi everyone,

My plan is to write some methods that use eigen and create a class library dll that gets called from a c# program. I had it working when I was using MatrixXf, but when I use SparseMatrix, I get the following error:

AccessViolationException was unhandled
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The c# code that calls the method resembles the following:
Code: Select all
            unsafe
            {
                fixed (float* oldPointer = &oldData[0])
                {
                    fixed (float* newPointer = &newData[0])
                    {
                        someclass.somemethod(newPointer, oldPointer);
                    }
                }
            }


and in the .dll file I have something like the following:
Code: Select all
void someclass::somemethod(float outArray[], float inarray[])
{

 SparseMatrix<float> A(L, L);
 A.coeffRef(0, 0) = 1;
}

where the error is caused by the line
Code: Select all
A.coeffRef(0, 0) = 1;

whereas something like
Code: Select all
void someclass::somemethod(float outArray[], float inarray[])
{
 MatrixXf A(L, L);
 A(0, 0) = 1;
}

works fine. I realize that C# probably doesn't approve of something about how sparse matrices are stored in memory, but might there be an easy workaround?
jctaft
Registered Member
Posts
2
Karma
0
oops, needed to declare it as DynamicSparseMatrix in order to define its indices like that.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft