exc bad access - EXC_BAD_ACCESS error on fwrite using underlying array from vector class -
i stumped exc_bad_access error. using zlib compress , save data array ch in function deflatereadout called function generate. program fails @ fwrite on marked line.
class wsumap { public: vector<vector <unsigned char> > chunk; int xcomp[4]; int ycomp[4]; vector<int> priority; hash hashchunk; wsumap() { chunk.resize(4); chunk[0] = vector<unsigned char>(chunk); chunk[1] = vector<unsigned char>(chunk); chunk[2] = vector<unsigned char>(chunk); chunk[3] = vector<unsigned char>(chunk); priority.push_back(0); priority.push_back(1); priority.push_back(2); priority.push_back(3); xcomp[0] = -1; xcomp[1] = -1; xcomp[2] = -1; xcomp[3] = -1; ycomp[0] = -1; ycomp[1] = -1; ycomp[2] = -1; ycomp[3] = -1; } void generate() { (int = 0; i<chunk; i++) { chunk[0][i]=100; } (int = 0; < 16; i++) { (int j = 0; j < 16; j++) { cout << chunk[0][0] << endl; unsigned char* ch = &chunk[0][0]; cout << ch[0] << endl; deflatereadout(i, j, &chunk[0][0]); } } } void deflatereadout(int x, int y, unsigned char* ch) { int ret, flush; unsigned have; z_stream strm; vector<unsigned char> out = vector<unsigned char>(chunk); out.resize(chunk); /* allocate deflate state */ strm.zalloc = z_null; strm.zfree = z_null; strm.opaque = z_null; ret = deflateinit(&strm, z_default_compression); if (ret != z_ok) assert(true); //return ret; ostringstream oss; oss << "map/" << x << "x" << y; string str = oss.str(); cout << str << endl; file* dest = fopen(str.c_str(), "w"); /* run deflate() on input until output buffer not full, finish compression if of source has been read in */ { strm.avail_out = chunk; strm.avail_in = chunk; strm.next_in = ch; strm.next_out = &out[0]; ret = deflate(&strm, z_finish); /* no bad return value */ assert(ret != z_stream_error); /* state not clobbered */ have = chunk - strm.avail_out; if (fwrite(&out[0], 1, have, dest) != have || ferror(dest)) {//error here (void) deflateend(&strm); //return z_errno; } } while (strm.avail_out == 0); assert(strm.avail_in == 0); /* input used */ /* clean , return */ (void) deflateend(&strm); }
thank can provide.
i figured out. trying write directory did not exist , thought automatically create if did not exist.
Comments
Post a Comment