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

Bad alloc error #5

Open
Harsharma2308 opened this issue Mar 14, 2019 · 0 comments
Open

Bad alloc error #5

Harsharma2308 opened this issue Mar 14, 2019 · 0 comments

Comments

@Harsharma2308
Copy link

Harsharma2308 commented Mar 14, 2019

I am always getting bad alloc error while building distance transform?
Any idea why is this happening? The number of points in my pointcloud are around 250 only.

Building Distance Transform...
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[1]    9507 abort

Problem occurs somewhere in the initiliasation of Array3d object.

void Array3d<T>::Init(int x, int y, int z)
{
  
	Xdim = x;
	Ydim = y;
	Zdim = z;
  // allocate the memory for the first level pointers.
  int n1 = z, n2 = y, n3 = x;


  data = new T** [n1];


  // set the first level pointers and allocate the memory for the second level pointers.

  {

    data[0] = new T* [n1 * n2];

    for (int row1_index = 0; row1_index < n1; row1_index++)
      data [row1_index] = data[0] + n2 * row1_index;
  }

  T* array_ptr = new T [n1*n2*n3];
  data_array = array_ptr;

  // set the second level pointers.
  for (int row1_index = 0; row1_index < n1; row1_index++)
    for (int row2_index = 0; row2_index < n2; row2_index++) {
      data [row1_index][row2_index] = array_ptr;
      array_ptr += n3;
    }
 
}

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