Menu

Possible bug in GLS.File3DS

lnebel
2025-08-04
2025-08-07
  • lnebel

    lnebel - 2025-08-04

    Hi,

    I think I have located a bug.

    In unit GLS.File3DS, at line 1536, shininess is assigned directly as a result of the MaxInteger function. However, shininess is limited to 0..128 (TGLShininess = 0..128), and if the result of MaxInteger is outside that range the code simply fails without and error. To fix it, I have added code to first read to a temporary variable and then check the range before assigning.

    I don't have rights to do the change in the code base, so could someone fix ths?

    function GetOrAllocateMaterial(materials: TMaterialList; const Name: string): string;
    var
    TmpShininess : Integer;
    .
    begin
    .
    .
    TmpShininess := MaxInteger(0, Integer(round((material.Shininess) * 128)));
    if (TmpShininess >= 0) and (TmpShininess <= 128) then begin
    Shininess := TmpShininess;
    end else begin
    Shininess := 0;
    end;
    .
    .
    end;

    Lars

     
  • Pavel Vassiliev

    Pavel Vassiliev - 2025-08-07

    Lars, we have a GLS.Material range limited to TGLShininess = 0..128, so the code will have a compiler error if the value is out of range during the design time, but the fix
    if (TmpShininess >= 0) and (TmpShininess <= 128) then
    Shininess := TmpShininess
    else
    Shininess := 0;
    in GLS.File3DS may be justified for binaries. Done. Check out the glsl DiffuseShader demo, for example.
    Pavel

     
  • lnebel

    lnebel - 2025-08-07

    Thanks Pavel, I don't know about the design time problem but for me the problem occurred when reading a 3ds file I saved from Blender years ago. Then, a few months ago the 3ds file could no longer be loaded and I recently located that the problem was the shininess property. There must have been a change in the code at some point? No errors were thrown so the error was not easy to locate. When debugging, I could see that the shininess value read from the file was in the thousands. I have no idea where that comes from but because of the missing range check the code failed.
    Lars

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.