• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Possible bug in CreateMultiImageFromGLTexture of ImagingOpenGL.pas

Started by Johannes, 7 February 2018, 02:42:04

Previous topic - Next topic

Johannes

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;


Galfar


Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk