godot icon indicating copy to clipboard operation
godot copied to clipboard

convert project to godot4 file.get_var()

Open jonSP12 opened this issue 2 years ago • 11 comments

Godot version

4.0 beta6

System information

windows 10 vulkan

Issue description

file.get_var() error when converting a project from 3.5 to 4.0

log in 3.5 "print(animFile)":

{Fnum:[{hEx:{fm:0, pa:0, pos:(0, -82), pz:9, scl:(1, 1), vs:False}, pt1:{dn1:(-3, 3), dn2:(0, 3), dn3:(3, 3), fm:0, md1:(-3, 0), md2:(0, 0), md3:(3, 0), pa:0, pos:(-1.5, -49.5), pz:0, up1:(-3, -3), up2:(0, -3), up3:(3, -3)}, pt10:{dn1:(-5, 2), dn2:(0, 2), dn3:(5, 2), fm:0, md1:(-5, -1), md2

log in 4 "print(animFile)":

[X: (0, 4747321238252559500000000000, 0), Y: (0, 0, 0), Z: (0, 0, 0), O: (0, 0, 0)]
[X: (0, 4747321238252559500000000000, 0), Y: (0, 0, 0), Z: (0, 0, 0), O: (0, 0, 0)]

Steps to reproduce

**-----------------------godot 3.5-----------------------------------

the function saves a strut has store.var**

func _saveAnim():
	if ( saveFileName == "" ):
		saveFileName = "noName";
	
	var file = File.new()
	file.open(saveFileName, File.WRITE)
	file.store_var(root1);
	file.close()
	saveLock = false;

the strut is something like:

var root1 = {
	'Fnum': [0]
}

func _AddAnimFrame():
	
	root1.Fnum.resize(animFrameMax);
	
	root1.Fnum[animFrameMax-1] = {
	"pt1": { "fm": dt1_Fm, "pos":dt1_Po, "pz": dt1_Z, "pa": dt1_A, "up1": dt1_Up1, "up2": dt1_Up2, "up3": dt1_Up3, "md1": dt1_Md1, "md2": dt1_Md2, "md3": dt1_Md3, "dn1": dt1_Dn1, "dn2": dt1_Dn2, "dn3": dt1_Dn3 },
	"pt2": { "fm": dt2_Fm, "pos":dt2_Po, "pz": dt2_Z, "pa": dt2_A, "up1": dt2_Up1, "up2": dt2_Up2, "up3": dt2_Up3, "md1": dt2_Md1, "md2": dt2_Md2, "md3": dt2_Md3, "dn1": dt2_Dn1, "dn2": dt2_Dn2, "dn3": dt2_Dn3 },....etc....etc....

#--------------------in Godot 4 loading the file and getting the var----------------------------

func _loadAnim( loadFileName ):
	var file = FileAccess.open(loadFileName, FileAccess.READ)
	var animFile  = file.get_var();
	print(animFile)
	file = null # File is closed.
	return( animFile );

the log shows error Fnum not found the print(animFile) [X: (0, 4747321238252559500000000000, 0), Y: (0, 0, 0), Z: (0, 0, 0), O: (0, 0, 0)] etc...etc...

Minimal reproduction project

**its a big project ( 3 at once ) 1 editor, 1game, the game converted to gd4 **

godot 3.5 minimal project example varSave.zip

godot 4 minimal project example varSave2.zip

#--------------IN GODOT 3.5--------

var root1 = {
	'Fnum': [0]
}

func _createAnim():
	root1.Fnum.resize(animFrameMax);
	for n in range(animFrameMax):
		root1.Fnum[n] = {
	"pt1": { "fm": dt1_Fm, "pos":dt1_Po, "pz": dt1_Z, "pa": dt1_A, "up1": dt1_Up1, "up2": dt1_Up2, "up3": dt1_Up3, "md1": dt1_Md1, "md2": dt1_Md2, "md3": dt1_Md3, "dn1": dt1_Dn1, "dn2": dt1_Dn2, "dn3": dt1_Dn3 },
	"pt2": { "fm": dt2_Fm, "pos":dt2_Po, "pz": dt2_Z, "pa": dt2_A, "up1": dt2_Up1, "up2": dt2_Up2, "up3": dt2_Up3, "md1": dt2_Md1, "md2": dt2_Md2, "md3": dt2_Md3, "dn1": dt2_Dn1, "dn2": dt2_Dn2, "dn3": dt2_Dn3 },
	"pt3": { "fm": dt3_Fm, "pos":dt3_Po, "pz": dt3_Z, "pa": dt3_A, "up1": dt3_Up1, "up2": dt3_Up2, "up3": dt3_Up3, "md1": dt3_Md1, "md2": dt3_Md2, "md3": dt3_Md3, "dn1": dt3_Dn1, "dn2": dt3_Dn2, "dn3": dt3_Dn3 },
	"pt4": { "fm": dt4_Fm, "pos":dt4_Po, "pz": dt4_Z, "pa": dt4_A, "up1": dt4_Up1, "up2": dt4_Up2, "up3": dt4_Up3, "md1": dt4_Md1, "md2": dt4_Md2, "md3": dt4_Md3, "dn1": dt4_Dn1, "dn2": dt4_Dn2, "dn3": dt4_Dn3 },
	"pt5": { "fm": dt5_Fm, "pos":dt5_Po, "pz": dt5_Z, "pa": dt5_A, "up1": dt5_Up1, "up2": dt5_Up2, "up3": dt5_Up3, "md1": dt5_Md1, "md2": dt5_Md2, "md3": dt5_Md3, "dn1": dt5_Dn1, "dn2": dt5_Dn2, "dn3": dt5_Dn3 },
	"pt6": { "fm": dt6_Fm, "pos":dt6_Po, "pz": dt6_Z, "pa": dt6_A, "up1": dt6_Up1, "up2": dt6_Up2, "up3": dt6_Up3, "md1": dt6_Md1, "md2": dt6_Md2, "md3": dt6_Md3, "dn1": dt6_Dn1, "dn2": dt6_Dn2, "dn3": dt6_Dn3 },
	"pt7": { "fm": dt7_Fm, "pos":dt7_Po, "pz": dt7_Z, "pa": dt7_A, "up1": dt7_Up1, "up2": dt7_Up2, "up3": dt7_Up3, "md1": dt7_Md1, "md2": dt7_Md2, "md3": dt7_Md3, "dn1": dt7_Dn1, "dn2": dt7_Dn2, "dn3": dt7_Dn3 },
	"pt8": { "fm": dt8_Fm, "pos":dt8_Po, "pz": dt8_Z, "pa": dt8_A, "up1": dt8_Up1, "up2": dt8_Up2, "up3": dt8_Up3, "md1": dt8_Md1, "md2": dt8_Md2, "md3": dt8_Md3, "dn1": dt8_Dn1, "dn2": dt8_Dn2, "dn3": dt8_Dn3 },
	"pt9": { "fm": dt9_Fm, "pos":dt9_Po, "pz": dt9_Z, "pa": dt9_A, "up1": dt9_Up1, "up2": dt9_Up2, "up3": dt9_Up3, "md1": dt9_Md1, "md2": dt9_Md2, "md3": dt9_Md3, "dn1": dt9_Dn1, "dn2": dt9_Dn2, "dn3": dt9_Dn3 },
	"hEx": { "fm": hExt1_Fm, "pos":hExt1_Po, "pz": hExt1_Z, "pa": hExt1_A, "scl": hExt1_Sc },
	"pt10": { "fm": dt10_Fm, "pos":dt10_Po, "pz": dt10_Z, "pa": dt10_A, "up1": dt10_Up1, "up2": dt10_Up2, "up3": dt10_Up3, "md1": dt10_Md1, "md2": dt10_Md2, "md3": dt10_Md3, "dn1": dt10_Dn1, "dn2": dt10_Dn2, "dn3": dt10_Dn3 },
	"pt11": { "fm": dt11_Fm, "pos":dt11_Po, "pz": dt11_Z, "pa": dt11_A, "up1": dt11_Up1, "up2": dt11_Up2, "up3": dt11_Up3, "md1": dt11_Md1, "md2": dt11_Md2, "md3": dt11_Md3, "dn1": dt11_Dn1, "dn2": dt11_Dn2, "dn3": dt11_Dn3 },
	"pt12": { "fm": dt12_Fm, "pos":dt12_Po, "pz": dt12_Z, "pa": dt12_A, "up1": dt12_Up1, "up2": dt12_Up2, "up3": dt12_Up3, "md1": dt12_Md1, "md2": dt12_Md2, "md3": dt12_Md3, "dn1": dt12_Dn1, "dn2": dt12_Dn2, "dn3": dt12_Dn3 },
	"pt13": { "fm": dt13_Fm, "pos":dt13_Po, "pz": dt13_Z, "pa": dt13_A, "up1": dt13_Up1, "up2": dt13_Up2, "up3": dt13_Up3, "md1": dt13_Md1, "md2": dt13_Md2, "md3": dt13_Md3, "dn1": dt13_Dn1, "dn2": dt13_Dn2, "dn3": dt13_Dn3 },
	"pt14": { "fm": dt14_Fm, "pos":dt14_Po, "pz": dt14_Z, "pa": dt14_A, "up1": dt14_Up1, "up2": dt14_Up2, "up3": dt14_Up3, "md1": dt14_Md1, "md2": dt14_Md2, "md3": dt14_Md3, "dn1": dt14_Dn1, "dn2": dt14_Dn2, "dn3": dt14_Dn3 },
	"pt15": { "fm": dt15_Fm, "pos":dt15_Po, "pz": dt15_Z, "pa": dt15_A, "up1": dt15_Up1, "up2": dt15_Up2, "up3": dt15_Up3, "md1": dt15_Md1, "md2": dt15_Md2, "md3": dt15_Md3, "dn1": dt15_Dn1, "dn2": dt15_Dn2, "dn3": dt15_Dn3 },
	"wp1": { "fm": wp1_Fm, "pos":wp1_Po, "pz": wp1_Z, "pa": wp1_A, "scl": wp1_Sc },
		}




func _saveAnim():
if ( saveFileName == "" ):
saveFileName = "noName";
var file = File.new()
file.open(saveFileName, File.WRITE)
file.store_var(root1);
file.close()
saveLock = false;
  • #--------------IN GODOT 4-----------
func _loadAnim( loadFileName ):
	var file = FileAccess.open(loadFileName, FileAccess.READ)
	var animFile  = file.get_var(); #------------------------error----
	print(animFile)
	file = null # File is closed.
	return( animFile );

G4ERROR

godot 4 doesnt have the strut when opening the var file from 3.5... ( error Fnum is missing )

jonSP12 avatar Nov 24 '22 14:11 jonSP12

@jonSP12 Please upload a minimal reproduction project to make this easier to troubleshoot.

The code samples you've pasted are not a complete minimal reproduction project, as they cannot be run as-is.

Calinou avatar Nov 24 '22 15:11 Calinou

the godot 3.5 file save in var --- file.store_var(); varSave.zip --------------------//-------//------------- godot 4 file load in var --- file.get_var(); varSave2.zip

4 loads the var file in 3.5... the save file extension is *.anim... when converting a project to gd4 the files *.anim seem remain identical. noteP

file.get_var() cant seem to read from 3.5

jonSP12 avatar Nov 24 '22 17:11 jonSP12

reUploaded the files in .zip

jonSP12 avatar Nov 24 '22 17:11 jonSP12

I was able to duplicate the problem, using the provided .zip files, on Linux (Pop_OS! 20.04), using Godot 3.5.1 and Godot 4.0-beta6.

The issue is that a (large, complex) Dictionary is written to a file using File::store_var() with Godot 3, and the file is read using FileAccess:get_var() with Godot 4. The variable that's read is completely different than the contents written.

daveTheOldCoder avatar Nov 25 '22 01:11 daveTheOldCoder

I found that calling typeof() on the variable that's passed to store_var() in Godot 3 returns 18, which is Variant.Type.TYPE_DICTIONARY.

Calling typeof() on the variable that's returned by get_var() in Godot 4 also returns 18, which in Godot 4 is Variant.Type.TYPE_TRANSFORM3D, not Variant.Type.TYPE_DICTIONARY.

That may be the cause of the problem. It looks like Variants are stored using the numeric type codes, which have changed between Godot 3 and Godot 4.

Should these Godot 4 enums be changed to avoid this compatibility issue?

References: https://docs.godotengine.org/en/stable/classes/class_%40globalscope.html#enum-globalscope-variant-type https://docs.godotengine.org/en/latest/classes/[email protected]#enum-globalscope-variant-type

daveTheOldCoder avatar Nov 25 '22 02:11 daveTheOldCoder

Yes... its using the 3D... godot4 posts the error in the log, i did not post the log earlier has i was trying to get rid of it... 3derr

jonSP12 avatar Nov 25 '22 08:11 jonSP12

Isn't it a typo in your code? Fnum for enum?

Zireael07 avatar Nov 25 '22 08:11 Zireael07

Isn't it a typo in your code? _F_num for enum?

Fnum ( frame number )

jonSP12 avatar Nov 25 '22 08:11 jonSP12

It has been tested saving the files in Gd3.5 has ConfigFile, then opening them in Gd4 and resave with file.store_var(); clears the error, the files are now Variant.Type.TYPE_DICTIONARY ( 27 )

jonSP12 avatar Nov 28 '22 11:11 jonSP12

That doesn't resolve the issue. It's a workaround that avoids using store_var in Godot 3 and get_var in Godot 4.

daveTheOldCoder avatar Nov 28 '22 15:11 daveTheOldCoder

That doesn't resolve the issue. It's a workaround that avoids using store_var in Godot 3 and get_var in Godot 4.

Yes, but its tested, the problem was Variant.Type 18

jonSP12 avatar Nov 28 '22 15:11 jonSP12

hoping this will be fixed soon. cant move to 4.x because of this

ugothmeex avatar Jan 08 '23 05:01 ugothmeex

Assuming that this issue will be fixed by resequencing the enums, I'm attempting to identify the relevant source files that would have to be changed.

Are these all of the files?

https://github.com/godotengine/godot/blob/master/core/extension/gdextension_interface.h https://github.com/godotengine/godot/blob/master/doc/classes/%40GlobalScope.xml https://github.com/godotengine/godot-docs/blob/master/classes/class_%40globalscope.rst

I've seen other places where an enum value is hardcoded in a comment, but I'm ignoring those.

daveTheOldCoder avatar Jan 08 '23 19:01 daveTheOldCoder

Superseded by https://github.com/godotengine/godot/issues/73530.

Calinou avatar Feb 17 '23 22:02 Calinou