[BUG FBC] -vec cmdline causes crash

General FreeBASIC programming questions.
Post Reply
Jattenalle
Posts: 54
Joined: Nov 17, 2023 14:41
Contact:

[BUG FBC] -vec cmdline causes crash

Post by Jattenalle »

Issue:
Program crash if -vec > 0 is used.

Affects:
GAS target x86
Note: (Others may be affected as well but -gen GAS -arch 32 reliably triggers the crash)

Description:
Code works with -vec 0 but crashes if -vec > 0 is used.

Minimum reproducible code:

Code: Select all

'// Specific FBC commandline parameters that triggers the crash: -gen GAS -fpu SSE -vec 2 -arch 32
'fbcs: -exx -g -gen GAS -fpu SSE -vec 2 -arch 32
'Triggers:
'// Aborting due to runtime error 12 ("segmentation violation" signal) in [...].bas::VECTOR_CONVERT()
'
type vec2f
	x as single
	y as single
end type
type vec2d
	x as double
	y as double
end type
function vector_convert overload (byval v as vec2d) as vec2f
	dim as vec2f r
	r.x = v.x
	r.y = v.y
	return r
end function
function vector_convert(byval v as vec2f) as vec2d
	dim as vec2d r
	r.x = v.x
	r.y = v.y
	return r
end function

dim as vec2d camera_dpos
dim as vec2f camera_spos

camera_spos = vector_convert(camera_dpos)
' Program received signal SIGSEGV, Segmentation fault.
' __Z14VECTOR_CONVERT5VEC2D@16 (V=...)
'     at E:\Programming\!random stuff\stuff.bas:16
' 16              r.x = v.x
SARG
Posts: 1822
Joined: May 27, 2005 7:15
Location: FRANCE

Re: [BUG FBC] -vec cmdline causes crash

Post by SARG »

It's an alignment problem.
A workaround by filling the stack with dummy parameters :

Code: Select all

'// Specific FBC commandline parameters that triggers the crash: -gen GAS -fpu SSE -vec 2 -arch 32
#cmdline "-gen GAS -fpu SSE -vec 2 -arch 32"
'Triggers:
'// Aborting due to runtime error 12 ("segmentation violation" signal) in [...].bas::VECTOR_CONVERT()
'
type vec2f
	x as single
	y as single
end type
type vec2d
	x as double
	y as double
end type
function vector_convert overload (byval v as vec2d,byval dum2 as longint,byval dum3 as integer) as vec2f
	dim as Integer a
	dim as vec2f r

	a=@v.x
	print a mod 16 ''if zero no problem

	r.x = v.x
	r.y = v.y

	return r
end function
function vector_convert(byval v as vec2f) as vec2d
	dim as vec2d r
	r.x = v.x
	r.y = v.y
	return r
end function

dim as vec2d camera_dpos
dim as vec2f camera_spos

camera_spos = vector_convert(camera_dpos,0,0)
print "end"
Post Reply