solucionado bug que provocaba un acceso de memoria inv?lido al borrar un puntero

a c?mic desde yacreader

solucionada la carga de las texturas por defecto en el primer render
This commit is contained in:
Luis Ángel San Martín 2012-10-03 22:31:21 +02:00
parent 91e97ba8ff
commit 4df1a53a49
3 changed files with 25 additions and 19 deletions

View File

@ -27,7 +27,7 @@ Comic::Comic(const QString pathFile)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Comic::~Comic() Comic::~Comic()
{ {
QThread::~QThread(); //QThread::~QThread();
/*delete _7z; /*delete _7z;
delete _7ze; delete _7ze;
delete bm;*/ //TODO safe delete delete bm;*/ //TODO safe delete

View File

@ -179,7 +179,7 @@ struct Preset pressetYACReaderFlowDownConfig = {
}; };
/*Constructor*/ /*Constructor*/
YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p) YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
:QGLWidget(QGLFormat(QGL::DoubleBuffer), parent),numObjects(0) :QGLWidget(QGLFormat(QGL::DoubleBuffer), parent),numObjects(0),lazyPopulateObjects(-1)
{ {
updateCount = 0; updateCount = 0;
config = p; config = p;
@ -217,6 +217,7 @@ YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
loaderThread->start();*/ loaderThread->start();*/
timerId = startTimer(16); timerId = startTimer(16);
} }
void YACReaderFlowGL::timerEvent(QTimerEvent * event) void YACReaderFlowGL::timerEvent(QTimerEvent * event)
@ -254,7 +255,10 @@ void YACReaderFlowGL::initializeGL()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//populate(284); //TODO esto es responsabilidad del usuario de la clase defaultTexture = bindTexture(QImage(":/images/defaultCover.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
markTexture = bindTexture(QImage(":/images/setRead.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
if(lazyPopulateObjects!=-1)
populate(lazyPopulateObjects); //TODO esto es responsabilidad del usuario de la clase
//float x = 0.5; //float x = 0.5;
//int i; //int i;
@ -512,7 +516,7 @@ void YACReaderFlowGL::draw()
glColor4f( 1.0, 1.0, 1.0, 1.0 ); glColor4f( 1.0, 1.0, 1.0, 1.0 );
glVertex2f( -0.03, 0.98); glVertex2f( -0.03, 0.98);
glVertex2f( 0.03, 0.98); glVertex2f( 0.03, 0.98);
glVertex2f( 0, 0.95); glVertex2f( 0, 0.949);
glEnd(); glEnd();
@ -676,10 +680,9 @@ void YACReaderFlowGL::populate(int n)
float x = 1; float x = 1;
float y = 1 * (700/480.0); float y = 1 * (700/480.0);
int i; int i;
GLuint cover = bindTexture(QImage(":/images/defaultCover.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
markTexture = bindTexture(QImage(":/images/setRead.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption);
for(i = 0;i<n;i++){ for(i = 0;i<n;i++){
insert("cover", cover, x, y); insert("cover", defaultTexture, x, y);
} }
/* /*
@ -698,11 +701,12 @@ void YACReaderFlowGL::populate(int n)
//worker->start(); //worker->start();
} }
void YACReaderFlowGL::reset() //TODO unbind textures void YACReaderFlowGL::reset()
{ {
loaded.clear(); loaded.clear();
for(int i = 0;i<numObjects;i++){ for(int i = 0;i<numObjects;i++){
deleteTexture(cfImages[i].img); if(cfImages[i].img != defaultTexture)
deleteTexture(cfImages[i].img);
} }
if(numObjects>0) if(numObjects>0)
delete[] cfImages; delete[] cfImages;
@ -848,7 +852,7 @@ void YACReaderFlowGL::keyPressEvent(QKeyEvent *event)
if(event->key() == Qt::Key_Left) if(event->key() == Qt::Key_Left)
{ {
if(event->modifiers() == Qt::ControlModifier) if(event->modifiers() == Qt::ControlModifier)
setCurrentIndex(currentSelected-10); setCurrentIndex((currentSelected-10<0)?0:currentSelected-10);
else else
showPrevious(); showPrevious();
event->accept(); event->accept();
@ -858,7 +862,7 @@ void YACReaderFlowGL::keyPressEvent(QKeyEvent *event)
if(event->key() == Qt::Key_Right) if(event->key() == Qt::Key_Right)
{ {
if(event->modifiers() == Qt::ControlModifier) if(event->modifiers() == Qt::ControlModifier)
setCurrentIndex(currentSelected+10); setCurrentIndex((currentSelected+10>=numObjects)?numObjects-1:currentSelected+10);
else else
showNext(); showNext();
event->accept(); event->accept();
@ -1068,11 +1072,13 @@ void YACReaderPageFlowGL::updateImageData()
void YACReaderPageFlowGL::populate(int n) void YACReaderPageFlowGL::populate(int n)
{ {
YACReaderFlowGL::populate(n); worker->reset();
if(lazyPopulateObjects!=-1)
YACReaderFlowGL::populate(n);
lazyPopulateObjects = n;
imagesReady = QVector<bool> (n,false); imagesReady = QVector<bool> (n,false);
rawImages = QVector<QByteArray> (n); rawImages = QVector<QByteArray> (n);
imagesSetted = QVector<bool> (n,false); //puede sobrar imagesSetted = QVector<bool> (n,false); //puede sobrar
} }

View File

@ -96,15 +96,13 @@ extern struct Preset pressetYACReaderFlowDownConfig;
class YACReaderFlowGL : public QGLWidget class YACReaderFlowGL : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
private: protected:
int timerId; int timerId;
/*** System variables ***/ /*** System variables ***/
CFImage dummy; CFImage dummy;
int viewRotateActive; int viewRotateActive;
float stepBackup; float stepBackup;
GLuint markTexture;
/*functions*/ /*functions*/
void calcPos(CFImage *CF,int pos); void calcPos(CFImage *CF,int pos);
void calcRV(RVect *RV,int pos); void calcRV(RVect *RV,int pos);
@ -115,7 +113,8 @@ private:
WidgetLoader * loader; WidgetLoader * loader;
int fontSize; int fontSize;
protected: GLuint defaultTexture;
GLuint markTexture;
void initializeGL(); void initializeGL();
void paintGL(); void paintGL();
void timerEvent(QTimerEvent *); void timerEvent(QTimerEvent *);
@ -124,6 +123,7 @@ protected:
public: public:
//number of Covers //number of Covers
int numObjects; int numObjects;
int lazyPopulateObjects;
bool showMarks; bool showMarks;
QVector<bool> loaded; QVector<bool> loaded;
QVector<bool> marks; QVector<bool> marks;
@ -287,7 +287,7 @@ public:
// returns FALSE if worker is still busy and can't take the task // returns FALSE if worker is still busy and can't take the task
bool busy() const; bool busy() const;
void generate(int index, const QString& fileName); void generate(int index, const QString& fileName);
void reset(){idx = -1;}; void reset(){idx = -1;fileName="";};
int index() const { return idx; }; int index() const { return idx; };
QImage result(); QImage result();
YACReaderFlowGL * flow; YACReaderFlowGL * flow;
@ -318,7 +318,7 @@ public:
// returns FALSE if worker is still busy and can't take the task // returns FALSE if worker is still busy and can't take the task
bool busy() const; bool busy() const;
void generate(int index, const QByteArray& raw); void generate(int index, const QByteArray& raw);
void reset(){idx = -1;}; void reset(){idx = -1; rawData.clear();};
int index() const { return idx; }; int index() const { return idx; };
QImage result(); QImage result();
YACReaderFlowGL * flow; YACReaderFlowGL * flow;