Segmentation Error using VideoBuf

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Segmentation Error using VideoBuf

mokashe.ram
Hi,

I am trying use VideoBuf Variable available in 'Video' unit but getting error "Program Received Signal SIGSEGV Segmentation fault".

----------------------------------------------------------------------------------------------

PROCEDURE blank_window(top_left_x,
                       top_left_y,
                       width,
                       height,
                       colour     : BYTE);

VAR
   x_offset,
   y_offset : BYTE;
   code     : WORD;

BEGIN
     FOR y_offset:=top_left_y TO (top_left_y+height) DO
     BEGIN
          FOR x_offset:=top_left_x TO (top_left_x+width) DO
          BEGIN
              {* MEM[$B800:(x_offset-1)*2
                        +(y_offset-1)*160]:=32;
               MEM[$B800:(x_offset-1)*2
                        +(y_offset-1)*160+1]:=colour*16; *}

               VideoBuf^[(x_offset-1)*2
                        +(y_offset-1)*ScreenWidth]:=Ord(32);
               VideoBuf^[(x_offset-1)*2
                        +(y_offset-1)*160+1]:=Ord(colour*16);

          END;
     END;
          UpdateScreen(false);
END;

----------------------------------------------------------------------
Thanks
Sudarshan
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Tomas Hajny-2
On Tue, May 20, 2014 14:25, [hidden email] wrote:


Hi,

> I am trying use VideoBuf Variable available in 'Video' unit but getting
> error *"Program Received Signal SIGSEGV Segmentation fault". *
 .
 .
>               {* MEM[$B800:(x_offset-1)*2
>                         +(y_offset-1)*160]:=32;
>                MEM[$B800:(x_offset-1)*2
>                         +(y_offset-1)*160+1]:=colour*16; *}
>
>               * VideoBuf^[(x_offset-1)*2
>                         +(y_offset-1)*ScreenWidth]:=Ord(32);
>                VideoBuf^[(x_offset-1)*2
>                         +(y_offset-1)*160+1]:=Ord(colour*16);*

As suggested in my post in the other thread about the Mem and MemW topic,
the two consecutive accesses to Mem[] should be preferably converted to
just one with VideoBuf, because the elements accessed by VideoBuf^ are
words (which in turn consist from one byte for the character code and
another byte for the colour attributes consisting of the background colour
in the upper nibble and foreground colour in the lower nibble). Moreover,
since the elements are words, you should not multiply the offset by two
any longer. This in turn gives you:

         VideoBuf^[(x_offset-1)
                  +(y_offset-1)*ScreenWidth]:=$20 or (colour * 16) shl 8;

This works as intended (now disregarding stuff like missing checking of
the provided parameters against ScreenWidth and ScreenHeight - calling the
routine above with too big parameters would indeed still give you a
SIGSEGV, but that's another story).

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

mokashe.ram
Thanks for Your Help,

But facing the same issue using the last post code :)
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Tomas Hajny-2
On Wed, May 21, 2014 08:16, mokashe.ram wrote:
> Thanks for Your Help,
>
> But facing the same issue using the last post code :)

Then please include fully compilable source which does not work for you. I
tested it yesterday by I adding a basic main program body with four lines
consisting of InitVideo, call of your procedure with valid arguments,
ReadLn to allow checking the output before program termination and
DoneVideo. This program ran successfully under MS Win 7 (it has "drawn"
the rectangle with chosen colour as expected and terminated without any
error).

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

mokashe.ram
This post was updated on .
Hi Tomas,

             I have done all my work with Free pascal but only one error which still i am not able to fix is MEM as i tried all the options which you suggest me (heartly thanks for that) but still i am not Getting exect solution for it.....Please see below fully compilable source in free pascal 2.6.4 using 'Video' unit on windows 7 and help me please...

     PROCEDURE window_object.appear;

VAR
   width_offset,
   height_offset    : BYTE;
   current_location : location_pointer;

BEGIN
     current_location:=first_location;
     FOR height_offset:=y TO (y+y_offset-1) DO
     BEGIN
          FOR width_offset:=x TO (x+x_offset-1) DO
          BEGIN
              // MEMW[$B800:(width_offset-1)*2
                  //       +(height_offset-1)*160]:=current_location^.code;
                  VideoBuf^[(width_offset-1)
                         +(height_offset-1)* ScreenWidth]:=Ord(current_location^.code);                current_location:=current_location^.next;
          END;
     END;
     current_location^.next:=NIL;
     UpdateScreen(false);
END;

 

Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

mokashe.ram
Hi Guys..Please Help

Thanks
Sud
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Tomas Hajny-2
In reply to this post by mokashe.ram
On Wed, July 2, 2014 14:32, mokashe.ram wrote:


Hi,

>              I have done all my work with Free pascal but only one error
> which still i am not able to fix is MEM as i tried all the options which
> you
> suggest me (heartly thanks for that) but still i am not Getting exect
> solution for it.....
 .
 .

I'm currently on holiday, but I'll have a look at your source after
getting back home if noone else solves your issue earlier (feel free to
remind me if you don't get any response if you don't get any response
within one week from now).

Tomas





_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

mokashe.ram
ok Thanks ,Tomas
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Mark Morgan Lloyd-5
In reply to this post by mokashe.ram
mokashe.ram wrote:
> Hi Tomas,
>
>              I have done all my work with Free pascal but only one error
> which still i am not able to fix is MEM as i tried all the options which you
> suggest me (heartly thanks for that) but still i am not Getting exect
> solution for it.....Please see below fully compilable source in free pascal
> 2.6.4 using 'Video' unit on windows 7 and help me please...
>
>  UNIT TestMem;
..

What's your error message and what line is it implicating?

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

mokashe.ram
 Hi,

      Its throwing 'Segmentation Error' every procedure whereever 'VideoBuf' is used Actually  i am migration my application from TP TO Free pascal for 32 bit OS but i am not able to fix MEM issue.
i am totaly blank now please suggest me the soluition to replace MEM/MEMW.


PROCEDURE window_object.appear;

VAR
   width_offset,
   height_offset    : BYTE;
   current_location : location_pointer;

BEGIN
     current_location:=first_location;
     FOR height_offset:=y TO (y+y_offset-1) DO
     BEGIN
          FOR width_offset:=x TO (x+x_offset-1) DO
          BEGIN
              // MEMW[$B800:(width_offset-1)*2
                  //       +(height_offset-1)*160]:=current_location^.code;
                  VideoBuf^[(width_offset-1)
                         +(height_offset-1)* ScreenWidth]:=Ord(current_location^.code);
               current_location:=current_location^.next;
          END;
     END;
     current_location^.next:=NIL;
     UpdateScreen(false);
END;

Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Mark Morgan Lloyd-5
mokashe.ram wrote:
>  Hi,
>
>       Its throwing 'Segmentation Error' every procedure whereever 'VideoBuf'
> is used Actually  i am migration my application from TP TO Free pascal for
> 32 bit OS but i am not able to fix MEM issue.
> i am totaly blank now please suggest me the soluition to replace MEM/MEMW.

Apologies if this is brief, I've got my own problems and rather a lot of
them.

Make sure that you read
http://www.freepascal.org/docs-html/rtl/video/index.html, in particular
the bit about what you have to do before referencing VideoBuf.

Tomas has put a lot of time and effort into trying to help you already.
I don't claim particular familiarity with the Video unit, but if you
want anybody to help then you need to do what he suggested a couple of
weeks ago: write a simple, compilable program (i.e. A SINGLE FILE OF NO
MORE THAN A DOZEN OR SO LINES) and post it here with a description of
what's going wrong.

Presenting us with a unit that can't be compiled and run in isolation
doesn't help us to help you. Also I'd suggest not using Video and CRT
together in your initial test code: you've already been warned that this
is a suspect combination and I'd strongly suggest getting the Video side
of things working before tinkering.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Segmentation Error using VideoBuf

Tomas Hajny-2
In reply to this post by Tomas Hajny-2
On 3 Jul 14, at 3:44, Tomas Hajny wrote:
> On Wed, July 2, 2014 14:32, mokashe.ram wrote:


Hi again,

> >              I have done all my work with Free pascal but only one error
> > which still i am not able to fix is MEM as i tried all the options which
> > you
> > suggest me (heartly thanks for that) but still i am not Getting exect
> > solution for it.....
>  .
>  .
>
> I'm currently on holiday, but I'll have a look at your source after
> getting back home if noone else solves your issue earlier (feel free to
> remind me if you don't get any response if you don't get any response
> within one week from now).

Alright, I've checked it now:

1) As already pointed out by Mark, your source is not compilable
although you claimed the opposite in your post. First, routines
Mouse_Enabled, Show_Mouse and Hide_Mouse are neither known by your
source nor needed in those places because unit Video already takes
care about the mouse cursor as needed on the particular platform
used).

2) As also mentioned by Mark, you should provide a test program
rather than a unit, or you should add a small test program using the
unit if absolutely necessary (to be honest, I don't understand why
the compiler refuses to compile it if changing it from a unit to a
program by removing "interface" and "implementation" keywords and
moving the "uses" section to the beginning - it complains about
constructor having to be used only for methods, although exactly the
same source is compiled happily in a unit???). Anyway, I changed

3) After fixing issues mentioned above, the compiler emits exactly
one warning when compiling the code. This warning (conversion about
pointers and ordinals not being portable) helps to locate something
that could indeed lead to a segmentation error (or at least certainly
not working as expected). Line  
"current_location^.code:=word(@VideoBuf^[P]);" should be (probably?)
changed to "current_location^.code:=VideoBuf^[P];" if it aims to read
character and attributes at the specified screen location. BTW, if I
understand the intention of the code, it's terribly inefficient, but
that's another thing.

4) The test part (originally located in the initialization part of
the unit, but moved to a test program by me) should be changed so
that it waits for some user interaction before you the final
DoneVideo call, because this call may destroy whatever you did
before. You should insert a call to something like ReadLn (waiting
for Enter) or ReadKey (waiting for any "regular" key) before the
DoneVideo call to see what the test does. Finally, the parameters of
Error_Message.Initialise should be probably better changed for a
bigger window size. If I did that, I could see a rectangle displayed.
It does not exactly what you expect it to do, but you should be
probably able to debug the issue from that point (_if_ you understand
what it does - frankly, I'm not completely convinced about that).

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal