[SOLVED] Get does not save current screen work page

General FreeBASIC programming questions.
Post Reply
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

[SOLVED] Get does not save current screen work page

Post by linuxanddos »

After running

Code: Select all

ScreenCopy 0, 1
ScreenSet 1, 0
I draw something at the hidden screen page.
Than I use the following line to save what I have drawn:

Code: Select all

get (0,0)-(width, hight), imagebuffer
Then I continue drawing.
Somewhere in the future, I try to reuse my saved imagebuffer:

Code: Select all

Put (0,0), imagebuffer, PSet
ScreenSet 0, 0 
ScreenSync     
ScreenCopy 1, 0
But now I can see the imagebuffer is pink aka empty. Why?

According to https://www.freebasic.net/wiki/KeyPgGetgraphics the get command saves pixels from the current working page I have drawn something before - so this should work, shouldn't it?

Where do I make a mistake?
Last edited by linuxanddos on May 11, 2024 12:51, edited 1 time in total.
fxm
Moderator
Posts: 12181
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Get does not save current screen work page

Post by fxm »

Your different information is a little surprising and confusing.
Just one small example highlighting your dysfunction (which other users could then comment on and correct) would be welcome.
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Get does not save current screen work page

Post by linuxanddos »

This code should generate a moving black rectangle with a white background.
But the background is pink - so this does not seems to work.
I know there are easier ways to generate a white background - but this is just a part of something more complex there it is necessary to save the background (for saving time by not redrawing it again and again) and sadly it is not possible to draw their elements directly to an image buffer.

My main question is how to get the line

Code: Select all

get (0,0)-(breite, hoehe), menubild_statischer_teil   '<========== THIS LINE DOES NOT WORK AS EXPECTED
working.

Code: Select all

#include once "fbgfx.bi"
Dim shared as boolean locked = false
dim shared as integer breite, hoehe 
	

Sub lockScreen()
	locked = true
	ScreenCopy 0, 1         
	ScreenSet 1, 0           
End Sub

Sub unlockScreen()
	ScreenSet 0, 0  
	ScreenSync            
	ScreenCopy 1, 0    
	locked = false
End Sub



Type Testobjekt extends object
	private:
		menubild_statischer_teil as Any Ptr
		menubild_statischer_teil_generiert as boolean
		declare sub Zeichnen(i as Double)
	public:
		declare sub Ausfuehren()
		declare Constructor ( )
		declare Destructor ( )
end Type 

Constructor Testobjekt ( )
	menubild_statischer_teil_generiert = false
	menubild_statischer_teil = ImageCreate(breite, hoehe)
End Constructor

Destructor Testobjekt ( )
	ImageDestroy menubild_statischer_teil
end Destructor


Sub Testobjekt.Zeichnen(i as Double)
	if not locked then lockscreen()
	
	'Puffer für statische Teile verwenden, sobald diese 1x gezeichnet worden sind. Dies erhöht die Framerate.
	if not menubild_statischer_teil_generiert then
		'Etwas zeichnen
		cls
		Line (0,0)-(breite, hoehe), RGB(255,255,255), BF
		
		'Bis hier her gezeichnetes speichern
		get (0,0)-(breite, hoehe), menubild_statischer_teil   '<========== THIS LINE DOES NOT WORK AS EXPECTED
		menubild_statischer_teil_generiert = true
	Else
		Put (0,0), menubild_statischer_teil, PSet
	end if
	
	'Dynamische Elemente zeichnen:
	Line (i*2,i)-(i,i*3), RGB(0,0,0), BF
	unlockscreen()
	sleep 10
end sub

Sub Testobjekt.Ausfuehren()
	dim i as double = 0
	do while i < 255 
		This.Zeichnen(i)
		i+=0.1
	loop
end sub


Declare Sub FensterOeffnen()
Sub FensterOeffnen()
	ScreenInfo breite, hoehe
	
	Print "Breite= " & breite
	Print "Hoehe = " & hoehe
	
	ScreenRes  breite,hoehe ,32,2, &h04 Or 8 
	Width breite\8, hoehe\16 ' für eine Schriftgröße von 8x16
End Sub

FensterOeffnen()
dim as Testobjekt testo
testo.Ausfuehren()
SARG
Posts: 1785
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Get does not save current screen work page

Post by SARG »

You get
Aborting due to runtime error 1 (illegal function call) at line 54
Try :

Code: Select all

get (0,0)-(breite-1, hoehe-1), menubild_statischer_teil 
fxm
Moderator
Posts: 12181
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Get does not save current screen work page

Post by fxm »

Well done SARG.

One can overflow (as you do) when drawing on a screen, but not in an image buffer.
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Get does not save current screen work page

Post by linuxanddos »

Code: Select all

get (0,0)-(breite-1, hoehe-1), menubild_statischer_teil 
Thank you, this solution is working.
Aborting due to runtime error 1 (illegal function call) at line 54
There did you see this error?
If I compile and run it on Linux, this is not shown. EDIT: Neither while compiling nor at runtime at the terminal emulator. Do I need to enable some debugging flag or something similar?

My FreeBasic version is: FreeBASIC-1.10.1-ubuntu-22.04-x86_64
fxm
Moderator
Posts: 12181
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Get does not save current screen work page

Post by fxm »

linuxanddos wrote: May 11, 2024 11:18

Code: Select all

get (0,0)-(breite-1, hoehe-1), menubild_statischer_teil 
Thank you, this solution is working.

My FreeBasic version is: FreeBASIC-1.10.1-ubuntu-22.04-x86_64

fxm wrote: Feb 19, 2016 17:43 However here are some behaviors of 'Get'/'Put' (graphics) learned by my experiment:
- Any 'Put' drawing which goes out of a graphic window induces no problem (the overflowing part appears nowhere), but this behavior is not from a requirement.
- Any 'Get' drawing which goes out of an image buffer (because of insufficient size) induces a memory overflow and the result is undefined (because of memory pollution).
- Any 'Put' drawing which goes out of an image buffer (because insufficient size) induces not any problem because the image source is clipped accordingly (already noted in documentation).
- The alone instruction 'Get' checks the validity of the provided coordinates and only at runtime (already noted in documentation).
fxm
Moderator
Posts: 12181
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Get does not save current screen work page

Post by fxm »

linuxanddos wrote: May 11, 2024 11:18
Aborting due to runtime error 1 (illegal function call) at line 54
There did you see this error?
If I compile and run it on Linux, this is not shown. EDIT: Neither while compiling nor at runtime at the terminal emulator. Do I need to enable some debugging flag or something similar?

My FreeBasic version is: FreeBASIC-1.10.1-ubuntu-22.04-x86_64

With the erroneous line:

Code: Select all

get (0,0)-(breite, hoehe), menubild_statischer_teil
a runtime error is generated if compiling with the '-exx' option.

See the GET documentation page:
Runtime errors:
Get throws one of the following runtime errors:

(1) Illegal function call
- dest is an array, but is not big enough to hold the image buffer.
- The upper-left or lower-right co-ordinates of the rectangle are outside the current clipping region (set or default). See View (Graphics).
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Get does not save current screen work page

Post by linuxanddos »

With your help and information I found some other, similar errors in my code.
Post Reply