I'm gonna get laughed at, but what the heck...
When an object dynamically allocates an sf::image and then deletes it, I get the following error:
An internal OpenGL call failed in Image.cpp (769) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
Posting the whole code wouldn't really be feasible, so I'll post the relevant stuff.
Object using the Wrapper Object,
please note that Image is in this case is not the sf::Image, but a "wrapper-class":
rect = _rect;
img.remake(rect.toSize(), clr);
Rectangle destBar(2, 2, rect.w - 2, rect.h - 2);
/// background
Image(*api, Size(rect.w - 4, 20), Color(0x00, 0x20, 0x60)).copyImageTo(img, destBar);
title.location = PointF((float)rect.x + 4, (float)rect.y + 4);
/// title seperator
Image(*api, Size(rect.w - 6, rect.h - 27), Color(0x00, 0xB0, 0xF0)).copyImageTo(img, Rectangle(3, 24, rect.w - 4, rect.h - 27));
code from the "wrapper-class"
Image::~Image(){
if (imageHandle){
std::cout << "info: " << info << std::endl << toString() << std::endl;
api->deleteImage(this);
std::cout << "image dtor called\n";
}
}
void Image::loadImage(const char * filename){
api->loadImage(this, filename);
info = filename;
}
and finally the code from the api-plugin:
loading an Image:
void PCOUT loadImage(fsa::Image * image, const char * filename){
debugReport << "Atempting to load " << filename << std::endl;
bool sucess;
if (image->imageHandle)
deleteImage(image);
image->imageHandle = new sf::Image;
sucess = image->imageHandle->LoadFromFile(filename);
if (sucess){
//masterFrames.push_back(newFrame);
//image->imageHandle->LoadFromFile(filename) = &masterFrames.at(masterFrames.size() - 1);
debugReport << "Loaded to address: " << image->imageHandle << std::endl;
} else {
/// image has value, won't get here without allocation taking place for the image
deleteImage(image);
debugReport << "Cannot load image: " << filename << std::endl;
}
}
the blank image, other images seem ok but deleting images this function generates seems to cause the error.
void PCOUT blankImage(fsa::Image * img, const fsaHelps::Size & sz, const fsaHelps::Color & clr){
if (img->imageHandle)
deleteImage(img);
debugReport << "Making blank image size of " << sz.toString() << " with color " << clr.toString() << std::endl;
img->imageHandle = new sf::Image(fsaHelps::fsa_abs(sz.w), fsaHelps::fsa_abs(sz.h), *(sf::Color *)(&clr));
}
deleting an Image:
void PCOUT deleteImage(fsa::Image * image){
debugReport << "Deleting Image\n";
delete image->imageHandle;
}
Is the problem visible? Being s--- code that it is, please send your criticisms (It helps
).
How should I fix this error?
Lemme know if you need access to the full source (GPLv3/LGPLv3 w/ static exception).
Thanks for your time, your criticisms and any ideas to fix this issue.
-Andy