Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 24th, 2005, 6:58 PM   #1
ionexchange
Newbie
 
Join Date: Oct 2005
Posts: 12
Rep Power: 0 ionexchange is on a distinguished road
SIGSEGV from std::~basic_string

Hello,
I am having a problem with this section of code.
for (int a = 0; a < old_d.size(); a++)
    {
      d_temp.push_back(old_d.at(a));
      boogie temp;
      temp.boogie_(old_d);
      od_frequency.push_back(temp);
    }
d_temp is a vector<drawing> and od_frequency is a vector<boogie>. So I'm making a DB of drawings one step at a time. Plus, I send that DB into a series of functions inside class boogie.
The class boogie looks like this:
class boogie{
public:
  frequency_ f;
  lo_four lf;
  derivitive_ d;
  void boogie_(vector<drawing> foo);
};
Here, the class function boogie_ takes the old_d (vector<drawing>) DB and does several things with them.
Class drawing looks like this
class drawing{
 public:
  string date;
  int tic[6];
  int PP;
};
When I run the code I keep getting a Segmentation fault just as I come out of temp.boogie_(old_d). I can run breakpoints all through temp.boogie_. When I come out of temp.boogie_ into main() is when I get the SIGSEGV error. The backtrace (from gdb) is as follows
#0 0x00ad0e9a in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
#1 0x0804a93f in drawing::~drawing ()
#2 0x0804d03f in std::_Destroy<drawing> ()
#3 0x0804ca17 in std::__destroy_aux<drawing*> ()
#4 0x0804bddc in std::_Destroy<drawing*> ()
#5 0x0804ade6 in std::vector<drawing, std::allocator<drawing> >::~vector ()
#6 0x0804a456 in main ()
When I change the code inside main() to read exactly as it would in temp.boogie_ (adjusting for class memeber names and stuff) I don't have any problems there, however I do have a SIGSEG error that is backtraced as follows
#0 0x0076f3dc in memcpy () from /lib/tls/libc.so.6
#1 0x0804c08a in std::_Construct<boogie, boogie> ()
#2 0x0804b08d in std::vector<boogie, std::allocator<boogie> >::push_back ()
#3 0x0804a5d9 in main ()
This can only occur when I push.back the vector<boogie>od_frequency.

Any sugestions, thanks.
Milt
ionexchange is offline   Reply With Quote
Old Oct 24th, 2005, 8:29 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Can you attach the entire source, so we can try it out, or is it too big?
It is possible that your heap is being corrupted before this point.
The Dark is offline   Reply With Quote
Old Oct 24th, 2005, 9:20 PM   #3
ionexchange
Newbie
 
Join Date: Oct 2005
Posts: 12
Rep Power: 0 ionexchange is on a distinguished road
Quote:
Originally Posted by The Dark
Can you attach the entire source, so we can try it out, or is it too big?
It is possible that your heap is being corrupted before this point.
It's kinda long. The only thing that realy happens before the code I quoted is that old_d is built from a file that is loaded. I know that part of the code works because I have used it in other programs that have worked without problems.
Here is the code that applies to boogie (essentially the new stuff I've programed). N is defined as const int N = 64. The function four1 is an external function that I know works. And Number is typedef float.
#include <string>
#include <fstream>
#include "fft.cpp"
using namespace std;
const int WHITE = 55;
const int RED = 42;

class drawing{
 public:
  string date;
  int tic[6];
  int PP;
};

class lo_four{
 public:
  Number wdata[2*N];
  Number rdata[2*N];
  void fft(int w[WHITE+1], int r[RED+1], int isign);
  void fft(Number w[WHITE+1], Number r[RED+1], int isign);
  void print_four(ofstream &wout, ofstream &rout);
};

class frequency_{
 public:
  int w[WHITE+1];
  int r[RED+1];
  void frequency(vector<drawing> p);
  void print_frequency(ofstream &out);
};

class derivitive_{
  public:
  Number dwdata[2*N];
  Number drdata[2*N];
  void derivitive(Number wdata[2*N], Number rdata[2*N]);
  void derivitive(lo_four curr, lo_four pre);
  void print_derivitive(ofstream &wout, ofstream &rout);
};

void lo_four::fft(int w[WHITE+1], int r[RED+1], int isign)
{
  for (int a = 0; a < 2*N; a++)
    {
      if (a < WHITE+1)
        {wdata[a]=w[a];}
      else
        {wdata[a]=0;}
      if (a < RED+1)
        {rdata[a]=r[a];}
      else
        {rdata[a]=0;}
    }
  four1(wdata,N,isign);
  four1(rdata,N,isign);
}

void lo_four::fft(Number w[WHITE+1], Number r[RED+1], int isign)
{
  for (int a = 0; a < 2*N; a++)
    {
      if (a < WHITE+1)
        {wdata[a]=w[a];}
      else
        {wdata[a]=0;}
      if (a < RED+1)
        {rdata[a]=r[a];}
      else
        {rdata[a]=0;}
    }
  four1(wdata,N,isign);
  four1(rdata,N,isign);
}

void lo_four::print_four(ofstream &wout, ofstream &rout)
{
  for (int a = 0; a < N; a++)
    {
      wout << wdata[a] << endl;
      rout << rdata[a] << endl;
    }
  return;
}


void frequency_::frequency(vector<drawing> p)
{
  for (int z = 0; z < WHITE+1; z++)
    {
      w[z]=0;
      if (z < RED+1)
        {r[z]=0;}
    }

  for (int a = 0; a < p.size(); a++)
    {
      for (int b = 0; b < 5; b++)
        {
          w[p.at(a).tic[b]]++;
        }
      r[p.at(a).tic[5]]++;
    }
  return;
}

void frequency_::print_frequency(ofstream &out)
{
  out << endl;
  out << "-------------------------------------------" << endl;
  out << "                  FREQUENCY                " << endl;
  out << "-------------------------------------------" << endl;
  out << "White:" << endl;
  for (int a = 1; a < WHITE+1; a++)
    {
      out << a << ": " << w[a] << "\t";
      if (!a%10)
        {out << endl;}
    }
  for (int b = 1; b < RED+1; b++)
    {
      out << b << ": " << r[b] << "\t";
      if (!b%10)
        {out << endl;}
    }
  return;
}

void derivitive_::derivitive(Number wdata[2*N], Number rdata[2*N])
{//gets the difference between real & imag four data points
  dwdata[0] = 0;
  drdata[0] = 0;
  for (int a = 1; a < 2*N; a++)
    {
      dwdata[2*a] = wdata[2*a] - wdata[2*(a-1)];
      dwdata[2*a+1] = wdata[2*a+1] - wdata[2*(a-1)+1];
      drdata[2*a] = rdata[2*a] - rdata[2*(a-1)];
      drdata[2*a+1] = rdata[2*a+1] - rdata[2*(a-1)+1];
    }
  return;
}

void derivitive_::derivitive(lo_four curr, lo_four pre)
{//gets the differenct between two separate four data points
  for (int a = 0; a < 2*N; a++)
    {
      dwdata[a] = curr.wdata[a] - pre.wdata[a];
      drdata[a] = curr.rdata[a] - pre.rdata[a];
    }
  return;
}

void derivitive_::print_derivitive(ofstream &wout, ofstream &rout)
{
  for (int a = 0; a < N; a++)
    {
      wout << dwdata[2*N] << endl;
      rout << drdata[2*N] << endl;
    }
  return;
}
Now, what I don't understand is that all of this code has been emplimented in my other programs, I'm just reorganizing this code for portablility. I have set breakpoints in all these functions listed above and the programs moves in and out of them no problem.
I hope this added info clarifies things.

Thanks again.
ionexchange is offline   Reply With Quote
Old Oct 24th, 2005, 9:34 PM   #4
ionexchange
Newbie
 
Join Date: Oct 2005
Posts: 12
Rep Power: 0 ionexchange is on a distinguished road
I found my problem. Thanks for your help. The error lies in derivitive(Number*, Number*); the loop should be N not 2*N. Thanks again.
ionexchange is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC