What does the Image class look like? It looks like VideoDevice has an Image member, right?
Printable View
What does the Image class look like? It looks like VideoDevice has an Image member, right?
Yes, the VideoDevice has an Image member, here is it:
Image.h
Image.cppCode:#ifndef IMAGE_H
#define IMAGE_H
#include <stdio.h>
#include <jpeglib.h>
class Image
{
public:
Image(unsigned char* data, int width, int height, int depth = 24);
~Image();
void convertToGray();
void save(const char* filename, int format = Image::JPEG, int jpegQuality = 80);
unsigned char* data;
int width;
int height;
int depth;
int size;
const static short int JPEG = 0;
const static short int PNM = 1;
protected:
private:
};
#endif // IMAGE_H
Code:#include "Image.h"
Image::Image(unsigned char* data, int width, int height, int depth)
{
this->data = data;
this->width = width;
this->height = height;
this->depth = depth;
this->size = width * height;
}
Image::~Image()
{
//dtor
}
void Image::convertToGray()
{
//TODO - fix seg fault in VideoDevice before
}
void Image::save(const char* filename, int format, int jpegQuality)
{
FILE* file = fopen(filename, "w");
if (format == Image::PNM)
{
fprintf(file, "P6\n%d %d\n255\n", width, height);
fwrite(data, width * height * 3, 1, file);
}
else if (format == Image::JPEG)
{
unsigned int lineSize = width * 3;
unsigned char* line;
struct jpeg_compress_struct compressInfo;
struct jpeg_error_mgr error;
compressInfo.err = jpeg_std_error(&error);
jpeg_create_compress(&compressInfo);
jpeg_stdio_dest(&compressInfo, file);
compressInfo.image_width = width;
compressInfo.image_height = height;
compressInfo.input_components = 3;
compressInfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&compressInfo);
jpeg_set_quality(&compressInfo, jpegQuality, true);
jpeg_start_compress(&compressInfo, true);
line = data;
for (int i = 1;i <= height;i++)
{
jpeg_write_scanlines(&compressInfo, &line, 1);
line = data + (lineSize * i);
}
jpeg_finish_compress(&compressInfo);
jpeg_destroy_compress(&compressInfo);
}
fclose(file);
}
Ehh... that doesn't help much. The destructor doesn't do anything.
The only thing I can think of is that you are overwriting memory or something, maybe with mbuffer?
My god, im so frustrated, is there any chance that the one who's messing up with my app is the Netbeans generated makefile? If i compile my application by hand it works... I'm so angry ¬¬.
Yes, very likely memory corruption.
Output the pointer value directly after creating the VideoDevice, and again directly before deleting it, and see if the values are the same.
Very strange. Electric Fence is supposed to diagnose the instant you step outside the bounds of allocated memory, yet it still falls over in free()
Only for heap overflows. But this could be a stack overflow overwriting the pointer itself. (Hmm ... but then it should overwrite the return address, too ...)
The address of VideoDevice before creating and before deleting it is the same.. I saw that if i call a method