Menu

TGLLines vs PFXSourceFX

Lazarus
Daniel
2018-06-27
2018-06-28
  • Daniel

    Daniel - 2018-06-27

    Hey!

    For some weird reason after the last GLScene update, there seems to be a problem with the TGLLines when a PFXSourceFX is spawning particles.
    I havn't figured out exactly what yet, but maybe you know a solution?

    This code stops working on a TGLLines object while a sourceFX is creating particles:

    for i := 0 to Lines1.Nodes.Count - 1 do
                   begin        
                   Lines1.Nodes.Items[i].Y := 0 + (random(50) - 22 * 10);
                   end;  
    end;
    

    Can it be related to the RandSeed bug as in this case: ?
    https://sourceforge.net/p/glscene/discussion/lazarus/thread/cc4be901/

    Cheers!

     
  • Daniel

    Daniel - 2018-06-27

    I see now that it is the random function which is not working while a PFXSource is creating particles.
    Is this a bug, or I'm I doing something wrong?
    If I call Randomize;
    I works a little better, but not good...

     
  • Jerome.D (BeanzMaster)

    Hi Daniel yes it's related Random function in Lazarus is not thread safe.Instead of Randomize/Random try to use TGLRandomNumGenerator in GLRandomGenerator unit.

    First try using preinit object

    uses  GLRandomGenerator;
    // GLS_RNG.Randomize;  normally not needed try if not work properly
    for i := 0 to Lines1.Nodes.Count - 1 do
                   begin        
                   Lines1.Nodes.Items[i].Y := 0 + (GLS_RNG.Random(50) - 22 * 10);
                   end;  
    end;
    

    if it not work

    Var
       MyRandomGen : TGLRandomGenerator.Create;
    
    MyRandomGen := TGLRandomGenerator.Create;
    //MyRandomGen.Randomize; // not needed it automatically call in create. call it a new time for regenerate new seed
    
    for i := 0 to Lines1.Nodes.Count - 1 do
                   begin        
                   Lines1.Nodes.Items[i].Y := 0 + (MyRandomGen.Random(50) - 22 * 10);
                   end;  
    end;
    
     

    Last edit: Jerome.D (BeanzMaster) 2018-06-27
  • Daniel

    Daniel - 2018-06-28

    Thanks Jerome!
    That solved quite a few more bugs I had, that I didn't understand.

    Cheers!!

     

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.