Hey Andreaz, would you test the following code for me and tell me if it works? In Turbo Delphi the game crashes as though the window isn't even shown. Only the particle system appears to do this, yet no error is raised! You can use a placeholder image for the sprite; it is just a round glow particle.

When I comment out the effect the application runs. Turn the effect addition code on and when it closes there's an invalid pointer operation error pointing nowhere. But as soon as I turn on the random additions of particles the application crashes like a rock! :s

Maybe you can find something I can't. (Also, the colors aren't object oriented like the particle example, so you might've weeded it out already. I can't tell with this past version.)

Edit
This exception seems to be the killer right here:
Code:
10:51:07 AM Error!: Access violation at address 00430230 in module 'GravityBombs.exe'. Read of address 00000004
The problem is right here (last line):
Code:
//------------------------------------------------------------------------------
function TPHXParticleManager.AddSystem(Effect: String; X, Y: Single): TPHXParticleSystem;
var System: TPHXParticleSystem;
begin
  System:= TPHXParticleSystem.Create(Self);
  System.Effect := Effects.Find(Effect);
And traced to (the for loop declaration):
Code:
function TPHXImageList.IndexOf(const Name: String): Integer;
var Index: Integer;
begin
  for Index:=0 to FImages.Count - 1 do begin
    if TPHXImage(FImages[Index]).Name = Name then begin
      Result:=Index;
      Exit;
    end;
  end;
  Result:=-1;
end;
Andreas!! The error is that you aren't creating an imagelist! Searching a nil pointer for a string is a painful crash. Goodness, there isn't even a parameter to pass one to the particle manager's constructor. I hope you've got an updated copy on hand. :lol:


I've updated the sourcecode and it is semistable now, but it still closes with that invalid pointer op message. :s At least I can see the effect now.
Code:
unit Main;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}    

interface

uses
  Classes, SysUtils,
  phxBase,
  phxImages,
  phxParticles,
  phxInput,
  phxTimer,
  phxMath,
  phxClasses,
  phxLogger,
  phxScreen;

const
  Gravity: TVector2f = (x: 0; y: -9.81); // Gravitic Constant of Earth in M/Sec^2 (Velocity)


procedure MainLoop;

implementation

//------------------------------------------------------------------------------
procedure MainLoop;
var Screen: TPHXScreen;
    Particles: TPHXParticleManager;
    Mouse: TPHXMouse;
    Keyboard: TPHXKeyboard;
    Timer: TPHXTimer;

    i,l: Word;
begin
  // Get the window
  Screen    := TPHXScreen.getInstance;
  Particles := TPHXParticleManager.Create;
  Mouse     := TPHXMouse.Create;
  Timer     := TPHXTimer.Create;
  Keyboard  := TPHXKeyboard.Create;

  Screen.VSync := True;
  Screen.DepthBits := 32;
  // Open the window
  if not Screen.Open('Gravity Bombs', -1, -1, 800, 600) then begin
    TPHXLogger.getInstance.Log(logSevere, 'Main', 'Unable to initialize form.');
    Exit;
  end;

//  with Particles.Effects.Add do begin
//    TPHXLogger.getInstance.Log(logInfo, 'Main', 'Loading comet particle...');
//    LoadFromFile('comet.phxpar');
//    Name := 'Comet';
//    GrowthMin := -16;
//    GrowthMax := -16;
//    Texture := 'particle.png';
//  end;

  if not Assigned(Particles.Images) then begin
    Particles.Images := TPHXImageList.Create;
    TPHXLogger.getInstance.Log(logWarning, 'Main', 'Imagelist is nil; initializing.');
  end;
  Particles.Images.LoadImage('particle.png').UpdatePatterns;

  l := 0;

  with Particles.Effects.Add do begin
    Name := 'Comet';
    Quota := 500;
    EmissionRate:= 100;
    Texture := 'particle.png';
    Blending := bmAdd;
    DurationMin := 0.50;
    DurationMax := 0.75;
    Direction := -90;
    SpreadMin := 360;
    SpreadMax := 360;
    VelocityMin := 72;
    VelocityMax := 84;
    TimeToLiveMin := 0.5;
    TimeToLiveMax := 0.5;
    SizeMin := 32;
    SizeMax := 32;
    GrowthMin := -12;
    GrowthMax := -16;
    NumColors := 3;
    Colors[0] := Color4f(0.7,0.8,1.0,0.6);
    Colors[1] := Color4f(0.6,0.7,0.9,0.6);
    Colors[2] := Color4f(0.1,0.2,0.5,0.6);
  end;

  Randomize;

  repeat
    Timer.Update;
    Mouse.Update;
    Keyboard.Update;

    if Random&#40;200&#41; <100> 0 then
      for I &#58;= 0 to Particles.Count - 1 do
        with Particles.Systems&#91;i&#93; do begin
          Position &#58;= VectorSub&#40;Position,VectorMul&#40;Gravity,Timer.FrameTime&#41;&#41;;
          if Position.Y > 650 then
            Particles.RemoveSystem&#40;Particles.Systems&#91;i&#93;&#41;;
        end;

    Particles.Move&#40;Timer.FrameTime&#41;;

    if l <> Particles.Count then begin
      l &#58;= particles.Count;
      Screen.Title &#58;= Format&#40;'Gravity Bombs &#91;%d active particle systems&#93;',&#91;l&#93;&#41;;
    end;

    // Clear the window
    Screen.Clear;

    Particles.Render;

    // Flip the buffers
    Screen.Flip;
  until &#40;Screen.Visible = False&#41;;

  Particles.Images.Free;
  Particles.Free;
  Keyboard.Free;
  Mouse.Free;
  Timer.Free;
  Screen.Free;
end;

end.