Draw string on buffer mistake, no warning?

General FreeBASIC programming questions.
Post Reply
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Draw string on buffer mistake, no warning?

Post by badidea »

I wrote this code. It freezes, without runtime errors.
The error is a missing "(i)" at the draw string buffer.
Shouldn't the compiler give a warning?

Code: Select all

#include "fbgfx.bi"

sub panic(text as string)
	print text
	getkey()
	end -1
end sub

const as long SW = 800, SH = 600
screenres SW, SH, 32
width SW \ 8, SH \ 16

const as long N_IMG = 10

dim as fb.image ptr pImg(N_IMG - 1)

for i as long = 0 to ubound(pImg)
	pImg(i) = imageCreate(12, 16)
	if pImg(i) = 0 then panic("Error: image create fail!")
	draw string pImg, (2, 0), str(i)
	put(i * 20, 0), pImg(i), pset
next

for i as long = 0 to ubound(pImg)
	imageDestroy(pImg(i))
	pImg(i) = 0
next

getkey()
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Draw string on buffer mistake, no warning?

Post by dodicat »

I get

Aborting due to runtime error 12 ("segmentation violation" signal) in ... [path to my .bas file]

Press any key to continue . . .

Win 10
fbide.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Draw string on buffer mistake, no warning?

Post by badidea »

But that is not a Freebasic runtime error. That is Windows saying something went horribly wrong.
My linux PC was just flabbergasted and did not say a word.
Oh, when I disable "-exx" I get "Segmentation fault (core dumped)".
So, "-exx" may block some bad things, but without much feedback.
Last edited by badidea on Mar 09, 2021 18:27, edited 1 time in total.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: Draw string on buffer mistake, no warning?

Post by dafhi »

wondered if it had to do with optional parameter so i tried
line pImg,(2, 0)-(1,1)

same result
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Draw string on buffer mistake, no warning?

Post by fxm »

This behavior is common to all graphics keywords that use an image buffer as a parameter.

In FreeBASIC, image buffers can be provided through arrays (old method as in QB) or through pointers (new method).

When parsing such an instruction line with an array name of pointers as an argument instead of an element name in the array of pointers, the compiler understands than the image buffer passed is the memory corresponding to the ensemble of the array elements (the old method to pass an image buffer).
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Draw string on buffer mistake, no warning?

Post by dodicat »

badidea wrote:But that is not a Freebasic runtime error. That is Windows saying something went horribly wrong.
My linux PC was just flabbergasted and did not say a word.
Oh, when I disable "-exx" I get "Segmentation fault (core dumped)".
So, "-exx" may block some bad things, but without much feedback.
I think it is a freebasic error

Code: Select all


print "hello"
error 12 
However I agree it is not very helpful, but more helpful than those cryptic errors from the gcc team.
Also it depends on your console/terminal staying open, in windows that depends on your ide, in Linux I think it remains open anyway?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Draw string on buffer mistake, no warning?

Post by fxm »

Yes, it is a FreeBASIC error message that may or may not appear, depending on where the overflow occurs outside of data of the array falsely passed as an image buffer.
Post Reply