Hi,

In one app I am porting code from jave to c++.The program compile fine but crashes when it enters into the ported code section.I use STL linked list implementation from here:
http://www.syncdata.it/stlce/stl_wce.zip

Java code:

LinkedList toProcessx;
LinkedList toProcessy;

void phaseUnwrap() 
{
  int startX = inputWidth / 2;
  int startY = inputHeight / 2;

  toProcessx = new LinkedList();
  toProcessy = new LinkedList();
  toProcessx.add(new int[]{startX});
  toProcessy.add(new int[]{startY});
  
  process[startX][startY] = false;
 //println("StartX" + startX);
  while (!toProcessx.isEmpty())
  {
    int[] x1 = (int[]) toProcessx.remove();
    int[] y1 = (int[]) toProcessy.remove();
    int x = x1[0];
    int y = y1[0];
    float r = phase[y][x];
    
    if (y > 0)
      phaseUnwrap(r, x, y-1);
    if (y < inputHeight-1)
      phaseUnwrap(r, x, y+1);
    if (x > 0)
      phaseUnwrap(r, x-1, y);
    if (x < inputWidth-1)
      phaseUnwrap(r, x+1, y);
  }
}

void phaseUnwrap(float basePhase, int x, int y) 
{
  if(process[y][x]) 
  {
    float diff = phase[y][x] - (basePhase - (int) basePhase);  
    if (diff > .5)
      diff--;
    if (diff < -.5)
      diff++;
    phase[y][x] = basePhase + diff;
    process[y][x] = false;
   // toProcessx.add(new int[]{x});
   // toProcessy.add(new int[]{y});
   toProcessx.add(new int[]{x});
   toProcessy.add(new int[]{y});
  }
}

Ported C++ code using linked list STL library

int inputwidth = 480;
int inputheight = 640;

 list<int> toProcessx;
 list<int> toProcessy;
 int startX = inputwidth / 2;
 int startY = inputheight / 2;


 void phaseUnwrap2(float basePhase, int x, int y) 
{
  if(process[y][x]) 
  {
    float diff = phase[y][x] - (basePhase - (int) basePhase);
   
    if (diff > .5)
      diff--;
    if (diff < -.5)
      diff++;
    phase[y][x] = basePhase + diff;
    process[y][x] = 0;//false;
    //toProcess.add(new int[]{x, y});
    toProcessx.push_back(x);
  }
} 
void phaseUnwrap(void) 
{
  toProcessx.push_back(startX);
  toProcessy.push_back(startY);
  process[startX][startY] = 0;//false;
 //println("StartX" + startX);
  while (!toProcessx.empty())
  {
    int *x1,*y1;
	x1 = toProcessx.front;
	y1 = toProcessx.front;
	toProcessx.pop_front();
	toProcessy.pop_front();
	//int *y1 = toProcessy.front;
	//int *y1 = toProcessx.remove(toProcessy.front);
    //int xy[2];
    int x = x1[0];
    int y = y1[0];
    float r = phase[y][x];
    
    if (y > 0)
      phaseUnwrap2(r, x, y-1);
    if (y < inputheight-1)
      phaseUnwrap2(r, x, y+1);
    if (x > 0)
      phaseUnwrap2(r, x-1, y);
    if (x < inputwidth-1)
      phaseUnwrap2(r, x+1, y);

    printf("X = %d  Y= %d\n",x,y);

	toProcessx.push_back(x);
	toProcessx.push_back(y);

  }
}

Could some one please tell me what is going wrong?

Thanks in advance

What's the error code you get?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.