Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: GLU Tesselation problem

  1. #1

    GLU Tesselation problem

    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.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  2. #2

    GLU Tesselation problem

    In my programs I have found those misterious errors which are solved switching 2 lines of code :? Sometimes the compiler does weird things.

    But it could also be memory corruption in your code that doesn't crash until that line is removed... try debugging with MemProof, I found Delphi's debugger is not enough to catch every problem. Also Fast Memory Manager could help you better if it's a matter of memory corruption.

  3. #3

    GLU Tesselation problem

    i have no idea what it is, i remove that and the program disappears crashing in totally silence, if i run with delphi's debugger it tells me weird AV error message on addresses way beyond application's range..
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  4. #4

    re-

    It happens to me one or two times; I think this is related to a bad pointer access or bad stack memory access.

    In your case i think the problem is you are defining everithing in a local stack procedure ( TForm1.BitBtn1Click ), probably including the showmessage procedure makes the compiler build the stack size in a way that hide the problem.

    I have not idea how much the variable Tess grow in size but most likely it is passing the stack size; try to move the variable tess: GLUtesselator as global, up after the Form1: TForm1;


    good luck.

  5. #5

    Re: re-

    Quote Originally Posted by tpascal
    It happens to me one or two times; I think this is related to a bad pointer access or bad stack memory access.

    In your case i think the problem is you are defining everithing in a local stack procedure ( TForm1.BitBtn1Click ), probably including the showmessage procedure makes the compiler build the stack size in a way that hide the problem.

    I have not idea how much the variable Tess grow in size but most likely it is passing the stack size; try to move the variable tess: GLUtesselator as global, up after the Form1: TForm1;


    good luck.
    i tried making all procedures global, same effect, also tess does not grow at all.. it is just a identifier / pointer, variable poly however grows, to 96 bytes only.. and i allocated much more data in local procedures.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  6. #6

    GLU Tesselation problem

    maybe because you're using nested procedures as callbacks? I think it's disallowed, you bypass the compiler by putting "@" in front of the function...probably the stack gets corrupted and you're only lucky it gets executed ok with that last line present.....if it's not the case, then only disassembly could give you a hint on what's wrong....

  7. #7

    GLU Tesselation problem

    my gluTessBeginPolygon looks like this:
    procedure gluTessBeginPolygon( tess: GLUtesselator; gon_data: Pointer ); stdcall;
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  8. #8

    GLU Tesselation problem

    Quote Originally Posted by JSoftware
    my gluTessBeginPolygon looks like this:
    procedure gluTessBeginPolygon( tess: GLUtesselator; gon_data: Pointer ); stdcall;
    you use that definition if you use GLU_TESS_BEGIN_DATA, GLU_TESS_BEGIN is different.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  9. #9

    GLU Tesselation problem

    Quote Originally Posted by Delfi
    Quote Originally Posted by JSoftware
    my gluTessBeginPolygon looks like this:
    procedure gluTessBeginPolygon( tess: GLUtesselator; gon_data: Pointer ); stdcall;
    you use that definition if you use GLU_TESS_BEGIN_DATA, GLU_TESS_BEGIN is different.
    Well that doesn't make much sense to me. All I know is that your code compiles for me using the abovementioned calling convention passing nil to gon_data and it works fine.

    Would stdcall make your call pass too few parameters on the stack?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #10

    GLU Tesselation problem

    I don't know what you did, please post the code, it crashes for me if i use your function definition (AND remove the last showmessage line).

    edit: are you by any chance using different glu.dll?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •