在Linux嵌入式ARM平台上使用OpenGL ES 2.0调试用Qt编写的应用程序时,我注意到当重复加载和卸载纹理时,我正在处理的嵌入式平台开始表现得很奇怪。因此,我写了一个简单的测试代码来强调OpenGL库:
的main.cpp
#include <QApplication>
#include "mainwidget.h"
int main(int argc, char** argv)
{
QApplication a(argc, argv);
MainWidget widget;
widget.showFullScreen();
return a.exec();
}
和mainwidget.h:
#include <QElapsedTimer>
#include <QTimer>
#include "mainwidget.h"
MainWidget::MainWidget(QWidget *parent) :
QGLWidget(parent)
{
makeCurrent();
QTimer* t = new QTimer();
t->setSingleShot(false);
t->setInterval(10);
connect(t, SIGNAL(timeout()), this, SLOT(textureLoadingTest()));
t->start();
}
void MainWidget::textureLoadingTest()
{
QImage image(256, 512, QImage::Format_ARGB32);
image.fill(Qt::red);
QElapsedTimer timer;
timer.start();
GLuint code = bindTexture(image);
qDebug("Texture loaded in %lldms to code = %u.", timer.elapsed(), code);
deleteTexture(code);
}
此代码似乎在20/30数千个纹理后完全崩溃了系统。 这是测试代码中的错误还是系统问题?