0
votes

I've got a very stark class.

unit StuffClass;

{$mode objfpc}{$H+}

interface

type
  TStuffClass = class
    public
      procedure Update;
  end;

implementation

procedure TStuffClass.Update;
begin

end;

end.

Creating an instance of it, and calling its Update procedure causes the program to SIGSEGV..

What the..? It's doing absolutely nothing.

I am using the Freepascal (& Lazarus) 32 bit version.

Why does it do this?

EDIT: Here is the calling bit:

//Creating it
constructor TEngine.Create(TV: pSDL_Surface);
begin
  Self.TV := TV;
  Self.StuffClass.Create;
end;

function TEngine.Update: Boolean;
begin
  WriteLN('Test');
  SDL_PumpEvents;

  Self.StuffClass.Update; //Crashes here.
  Update := True;
end;
1

1 Answers

1
votes

You're creating it wrong.

You need to store the returned object instance to a variable, and then use that variable (reference) instead:

constructor TEngine.Create(TV: pSDL_Surface);
begin
  Self.TV := TV;
  Self.StuffClass := TStuffClass.Create;
end;

Now the rest of your code can use it:

procedure TEngine.SomeOtherProcedure;
begin
  Self.StuffClass.Update;
end;