AV/Crash Executing Scripts with Function Pointers and Accessing global variables.

Issue #2 duplicate
Former user created an issue

Script execution crashes if a function called via a function pointer accesses a global variable.

For convenience I attached a testcase: Copy it into "Tests\SimpleScripts"-Directory and it will crash executing the script (compiles without errors). Tested with the svn-revision R2530 (April 2014).

Some notes: 1. It will not crash (test passes), if function "Setting" is called directly (not as a function pointer) 2. It will not crash (test passes), if you execute the content of the "DoIt"-function directly (one nesting level fewer).


type TSettingFunction = function(): Boolean;

type TFooObject = class FValue: Integer; constructor Create(A: Integer); begin FValue := A; end; function Value: Integer;
begin Result := FValue; end; end;

var AFoo: TFooObject = nil; function Foo: TFooObject; begin if AFoo = nil then AFoo := TFooObject.Create(42); Result := AFoo; end;

function Setting(): Boolean; begin PrintLn(IntToStr(Foo.Value)); Result := True; end;

procedure DoIt (); begin var SettingFunction: TSettingFunction = Setting; // Setting(); // Works SettingFunction(); // Crash
end;

DoIt();

Comments (2)

  1. Steffen Binas

    Please delete this issue in favor of the newer Issue #3 (I forgot to login, and cannot update my description)

  2. Log in to comment