Add proper resources cleaning

This commit is contained in:
luisangelsm
2026-01-17 23:03:56 +01:00
parent e6b7174c62
commit 65fd07bb99

View File

@ -51,6 +51,18 @@ YACReaderFlow3D::~YACReaderFlow3D()
killTimer(timerId); killTimer(timerId);
timerId = -1; timerId = -1;
} }
// Clean up image textures (not owned by Scene)
for (int i = 0; i < numObjects; i++) {
if (images[i].texture && images[i].texture != scene.defaultTexture.get()) {
delete images[i].texture;
}
}
images.clear();
numObjects = 0;
// Release all RHI resources
scene.reset();
} }
void YACReaderFlow3D::timerEvent(QTimerEvent *event) void YACReaderFlow3D::timerEvent(QTimerEvent *event)
@ -800,8 +812,15 @@ void YACReaderFlow3D::remove(int item)
} }
images.removeAt(item); images.removeAt(item);
if (texture != scene.defaultTexture.get()) if (texture != scene.defaultTexture.get()) {
// Remove shader bindings for this texture before deleting it
auto it = scene.shaderBindingsCache.find(texture);
if (it != scene.shaderBindingsCache.end()) {
delete it.value();
scene.shaderBindingsCache.erase(it);
}
delete texture; delete texture;
}
numObjects--; numObjects--;
} }
@ -869,9 +888,17 @@ void YACReaderFlow3D::reset()
currentSelected = 0; currentSelected = 0;
loaded.clear(); loaded.clear();
// Clean up image textures and remove their entries from shader bindings cache
for (int i = 0; i < numObjects; i++) { for (int i = 0; i < numObjects; i++) {
if (images[i].texture != scene.defaultTexture.get()) if (images[i].texture != scene.defaultTexture.get()) {
// Remove shader bindings for this texture before deleting it
auto it = scene.shaderBindingsCache.find(images[i].texture);
if (it != scene.shaderBindingsCache.end()) {
delete it.value();
scene.shaderBindingsCache.erase(it);
}
delete images[i].texture; delete images[i].texture;
}
} }
numObjects = 0; numObjects = 0;
@ -1398,12 +1425,14 @@ YACReaderPageFlow3D::~YACReaderPageFlow3D()
} }
rawImages.clear(); rawImages.clear();
// Clean up textures // Clean up textures and clear images to prevent double-delete in base destructor
for (auto &image : images) { for (auto &image : images) {
if (image.texture != scene.defaultTexture.get()) { if (image.texture != scene.defaultTexture.get()) {
delete image.texture; delete image.texture;
} }
} }
images.clear();
numObjects = 0;
} }
void YACReaderPageFlow3D::updateImageData() void YACReaderPageFlow3D::updateImageData()