ANDROID: Properly release texture resources

When calling glDeleteTextures() we need a valid surface.
This commit is contained in:
dhewg 2011-03-02 23:00:48 +01:00
parent c2d4cce429
commit 2d4a64d184
4 changed files with 32 additions and 25 deletions

View File

@ -124,10 +124,6 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
OSystem_Android::~OSystem_Android() {
ENTER();
delete _game_texture;
delete _overlay_texture;
delete _mouse_texture;
delete _savefile;
delete _timer;
delete _mixer;
@ -323,6 +319,10 @@ void OSystem_Android::initBackend() {
setupSurface();
_game_texture = new GLESPaletteTexture();
_overlay_texture = new GLES4444Texture();
_mouse_texture = new GLESPaletteATexture();
// renice this thread to boost the audio thread
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
warning("couldn't renice the main thread");
@ -400,9 +400,17 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
LOGD("initializing surface");
_game_texture->release();
_overlay_texture->release();
_mouse_texture->release();
JNI::deinitSurface();
setupSurface();
_game_texture->reinit();
_overlay_texture->reinit();
_mouse_texture->reinit();
event.type = Common::EVENT_SCREEN_CHANGED;
return true;
@ -410,15 +418,20 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
LOGD("deinitialiting surface");
_game_texture->release();
_overlay_texture->release();
_mouse_texture->release();
_screen_changeid = JNI::surface_changeid;
JNI::deinitSurface();
}
if (JNI::pause) {
// release some resources
// TODO
// free textures? they're garbled anyway since no engine
// respects EVENT_SCREEN_CHANGED
_game_texture->release();
_overlay_texture->release();
_mouse_texture->release();
LOGD("deinitialiting surface");
JNI::deinitSurface();
@ -573,6 +586,10 @@ void OSystem_Android::quit() {
_timer_thread_exit = true;
pthread_join(_timer_thread, 0);
delete _game_texture;
delete _overlay_texture;
delete _mouse_texture;
JNI::deinitSurface();
}

View File

@ -94,21 +94,6 @@ void OSystem_Android::setupSurface() {
GLCALL(glEnable(GL_TEXTURE_2D));
if (!_game_texture)
_game_texture = new GLESPaletteTexture();
else
_game_texture->reinitGL();
if (!_overlay_texture)
_overlay_texture = new GLES4444Texture();
else
_overlay_texture->reinitGL();
if (!_mouse_texture)
_mouse_texture = new GLESPaletteATexture();
else
_mouse_texture->reinitGL();
GLCALL(glViewport(0, 0, _egl_surface_width, _egl_surface_height));
GLCALL(glMatrixMode(GL_PROJECTION));

View File

@ -98,12 +98,15 @@ GLESTexture::GLESTexture() :
}
GLESTexture::~GLESTexture() {
release();
}
void GLESTexture::release() {
debug("Destroying texture %u", _texture_name);
GLCALL(glDeleteTextures(1, &_texture_name));
}
void GLESTexture::reinitGL() {
GLCALL(glDeleteTextures(1, &_texture_name));
void GLESTexture::reinit() {
GLCALL(glGenTextures(1, &_texture_name));
// bypass allocBuffer() shortcut to reinit the texture properly

View File

@ -42,7 +42,9 @@ public:
GLESTexture();
virtual ~GLESTexture();
virtual void reinitGL();
void release();
void reinit();
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,