i fixed the code to
if (pdata != NULL)
{
delete[] pdata;
pdata = NULL;
}
but still calling tex->~TGLTexture();
throws errors i cant access the tex then
let me show you
void AppendLayers(AnsiString fname)
{
layer_len = layer_len + 1;
TGLTexture * tmp = new TGLTexture[layer_len];
for (int i=0; i < layer_len-1; i++)
{
tmp[i].FileName = "1"; <- FileName is std::string <- i try to change that here is access violation whenever i use ~TGLTexture() in ResizeTexture() function but calling kill(), stores the object and there are no errors, i can access tmp[i]
tmp[i].LoadTGA(layers[i].FileName);
tmp[i].RelocateTo32Bit_from24();
if( (tmp[i].px_width != 256) || (tmp[i].px_height != 256) )
ResizeTexture(&tmp[i], 256);
}
delete [] layers;
layers = NULL;
layers = tmp;
layers[layer_len-1].LoadTGA(fname);
layers[layer_len-1].RelocateTo32Bit_from24();
TGLTexture testtga; testtga.LoadTGA(fname);
if( (testtga.px_width != 256) || (testtga.px_height != 256) )
ResizeTexture(&layers[layer_len-1], 256);
tmp = NULL;
ReInit_LayerMenu();
}
if someone wants:
[spoiler]
void ResizeTexture(TGLTexture * tex, int dim)
{
glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glActiveTexture(GL_TEXTURE0);
glViewport(0,0,dim,dim);
FULLSCREEN_SHADER->Enable();
FULLSCREEN_SHADER->Send1I(glGetUniformLocation(FULLSCREEN_SHADER->gProgram, "output_tex"), 0);
tex->Bind();
DrawFullScreenQuad(FULLSCREEN_SHADER);
FULLSCREEN_SHADER->Disable();
glViewport(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
tex->kill(); //~TGLTexture(); gives error
unsigned char * kpdata = new unsigned char[dim*dim*4]; //conversion to rgba anyway
glReadPixels(0, 0, dim, dim, GL_RGBA, GL_UNSIGNED_BYTE, kpdata);
tex->pdata = kpdata;
tex->px_width = dim;
tex->px_height = dim;
tex->bpp = 4;
glGenTextures(1, &tex->texture);
glBindTexture(GL_TEXTURE_2D, tex->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dim, dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex->pdata);
tex->texloaded = true;
PUSH_EVENT("Texture resized to 256x256");
}
[/spoiler]