I've created this very simple tesselator of convex polyons into concave ones using GLU, but it crashes if i remove the last showmessage line.. any ideas why?!?!?!?!?!?!?!?!


Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, opengl;

type

DVector = packed record
x, y, z: double;
end;

  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    output: TMemo;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  GLU_TESS_VERTEX_DATA = 100107; 

implementation

{$R *.DFM}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
tess: GLUtesselator;

   procedure tessError(errno : GLEnum); stdcall;
   begin
   showmessage('error, ERROR!');
   end;

   procedure ElementBegin (mode: GLenum); stdcall;
   begin
   unit1.Form1.output.lines.add('BEGIN ' + inttostr(mode));
   end;

   procedure ElementEnd; stdcall;
   begin
   unit1.Form1.output.lines.add('END');
   end;

  procedure ElementPrimitiveV2(vertexData : Pointer; polygonData : Pointer); stdcall;
   var
     pv: DVector;
   begin

   move(vertexData^, pv, sizeof(dvector));

   unit1.Form1.
   output.lines.add(
     format('%f %f %f', [
     pv.x,
     pv.y,
     pv.z])
   );

  end;
{
   procedure ElementPrimitive(vertexData : Pointer); stdcall;
   begin

   end;
}
var
poly: array of DVector;
i: integer;
begin
tess:= gluNewTess;

gluTessCallback(tess, GLU_TESS_BEGIN, @ElementBegin);
//gluTessCallback(tess, GLU_TESS_VERTEX, @ElementPrimitive); // directly to opengl...
gluTessCallback(tess, GLU_TESS_VERTEX_DATA, @ElementPrimitiveV2);
gluTessCallback(tess, GLU_TESS_END, @ElementEnd);
gluTessCallback(tess, GLU_TESS_ERROR, @tessError);

gluTessBeginPolygon(tess);
gluTessBeginContour(tess);

setlength(poly, 4);
poly[0].x:= 0;
poly[0].y:= 0;
poly[0].z:= 0;

poly[1].x:= 1;
poly[1].y:= 0;
poly[1].z:= 0;

poly[2].x:= 1;
poly[2].y:= 1;
poly[2].z:= 0;

poly[3].x:= 0;
poly[3].y:= 1;
poly[3].z:= 0;


for i:= 0 to high(poly) do begin
gluTessVertex(tess, @poly[i].x, @poly[i].x);
end;

gluTessEndContour(tess);
gluTessEndPolygon(tess);

gluDeleteTess(tess);

application.processmessages;

showmessage(output.lines.gettext); // UNCOMMENT ME = CRASH.

end;

end.