[fpc-pascal]FPC & DJGPP & GraphiX

Peter Beisel beisel at kbprueftechnik.frm.de
Wed May 22 13:20:02 CEST 2002


Hi all,
can anyone help?

compiler: FPC 1.0.4
target: DOS / Go32V2
graphix: 4.00

In my pascal main module (written with FPC) I want to call functions
from c-librarys (written
with DJGPP). In Textmode all works fine. Also the usage of the graph
unit is no problem.

BUT: using GraphiX doesn't work. The program crashes with runtime error
216.

After reducing the code now it seems clear that malloc/free called in a
c-librarys function
and the usage of grahpix doesn't work together - but why??

Any hint will help, regards Peter.


The c-library looks like that:

  File Lib1.c:
    /* lib1.c */
    #include <lib1.h>
    #include <stdlib.h>

    void fmallfree( long int i)   /* we test malloc & free */
    {
      void *mp;

      mp = malloc( i);
      free( mp);
    }

  file lib1.h:
    /* lib1.h */
    void fmallfree( long int i);


Here are 2 variations of code of the main program (both do crash):
A) calling fmallfree before opening graphix:
--------------------------------------------

    uses
      gxtext, gxType, graphix, crt;

    {$l lib1.o}
    {$linklib c}
    procedure fmallfree( i: longint); cdecl; external;

    var
      vgaFont : TFontVGA;

    begin
    // call external c-library function:
    fmallfree( 1000000);
    writeln( 'lib1 - fmallfree( 1000000) successfull called. Hit a key
to enter graphix.');
    readkey;

    // now entering graphix
    if InitGraphiX( ig_vesa, ig_lfb + ig_hwa) then
      begin
      if SetModeGraphiX( 800, 600, ig_col24) then
        begin
        vgaFont.loadFont;
        bar( 0,0,getMaxx,getmaxy, $FFFFFF);
        vgaFont.outText( 20,20, 'Testing GRAPHIX. Hit a key to
terminate',0);
        readkey;
        vgaFont.removeFont;
        graphix.initText;
        end;
      end;
    end.

This version crashes when calling the bar-function of graphix:
  Runtime Error 216
  barlm24, line 703 of graphixm.ppi


B) calling fmallfree within graphix running
--------------------------------------------

    uses
      gxtext, gxType, graphix, crt;

    {$l lib1.o}
    {$linklib c}
    procedure fmallfree( i: longint); cdecl; external;

    var
      vgaFont : TFontVGA;

    begin
    // first entering graphix
    if InitGraphiX( ig_vesa, ig_lfb + ig_hwa) then
      begin
      if SetModeGraphiX( 800, 600, ig_col24) then
        begin
        vgaFont.loadFont;
        bar( 0,0,getMaxx,getmaxy, $FFFFFF);
        vgaFont.outText( 20,20, 'Testing GRAPHIX. Hit a key to call
fmallfree',0);
        readkey;

        // call external c-library function:
        fmallfree( 1000000);
        vgaFont.outText( 20,60, 'lib1 - fmallfree( 1000000) successfull
called. Hit a key to terminate.',0);
        readkey;

        vgaFont.removeFont;
        graphix.initText;
        end;
      end;
    end.

This version crashes when calling the outText-function of graphix
after the call of fmallfree( 1000000):
  Runtime Error 216
  putpixel24, line 208 of .\lib\graphixl.ppi








More information about the fpc-pascal mailing list