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

Weird memory access Error #7

Open
parsarahimi opened this issue May 18, 2021 · 0 comments
Open

Weird memory access Error #7

parsarahimi opened this issue May 18, 2021 · 0 comments

Comments

@parsarahimi
Copy link

When you run the function ToMatrix twice, it gives memory access error, makes no sense.
I simplified the bug as much as possible, to reproduce it just use the following.
https://wasdk.github.io/WasmFiddle/

###############C++14###############
#include <math.h> 

void ToMatrix(double** M,double* V,int length)
{
  for (int i = 0; i < length; i++)
	{
		for (int j = 0; j < length; j++)
		{
			M[i][j] = V[i * length + j];
		}
	}
}

void myfunc(double* AT, int length)
{
	double** Matrix = new double* [length];
	for (int i = 0; i < length; i++)
	{
		Matrix[i] = new double[length];
  }
  
  ToMatrix(Matrix,AT,length);
	////Error comes when you do it twice
	ToMatrix(Matrix,AT,length);
	///
}
###############Javascript###############
var wasmModule = new WebAssembly.Module(wasmCode);
wasmInstance = new WebAssembly.Instance(wasmModule, wasmImports);

matrix1 = [[12,-51,4],[6,167,-68],[-4,24,-41]]
InputArray = new Float64Array(wasmInstance.exports.memory.buffer,0,9)
for (var i = 0; i < 3; i++) 
	{
	  for (var j = 0; j < 3; j++) 
	{
	  InputArray[3*i+j] = matrix1[i][j]
	}
}
log(InputArray)
wasmInstance.exports._Z6myfuncPdi(0,3);
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

1 participant