Vampyre Imaging Library Forum

Imaging Category => Bugs And Other Insects => Topic started by: Johannes on 7 February 2018, 02:42:04

Title: Possible bug in CreateMultiImageFromGLTexture of ImagingOpenGL.pas
Post by: Johannes on 7 February 2018, 02:42:04
I have looked into the code of ImagingOpenGL.pas and found something weird:

function CreateMultiImageFromGLTexture(const Texture: GLuint;
  var Images: TDynImageDataArray; MipLevels: LongInt; OverrideFormat: TImageFormat): Boolean;
var
  I, Width, Height, ExistingLevels: LongInt;
begin
  FreeImagesInArray(Images);
  SetLength(Images, 0);
  Result := False;
  if Byte(glIsTexture(Texture)) = GL_TRUE then
  begin
    // Check if desired mipmap level count is valid
    glBindTexture(GL_TEXTURE_2D, Texture);
    if MipLevels <= 0 then
      MipLevels := GetNumMipMapLevels(Width, Height);  //<- Here it tries to access uninitialized memory (Line 849)
    SetLength(Images, MipLevels);


A possible fix would be:
         
    if MipLevels <= 0 then
      begin
        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, @Width);
        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, @Height);
        MipLevels := GetNumMipMapLevels(Width, Height);
      end;

Title: Re: Possible bug in CreateMultiImageFromGLTexture of ImagingOpenGL.pas
Post by: Galfar on 23 August 2018, 14:17:52
Thanks for the report, just pushed your fix to the repo.