Skip to content

[VSCRIPT] Class instance serialisation error #219

@samisalreadytaken

Description

@samisalreadytaken

Describe the bug

Class instance member save/restore order is inconsistent. This issue is most apparent with an example.

Steps to reproduce

Save the following class instance, observe the member ordering. Note that member names are numbers for clarity as the hashed order of strings is not obvious.

class CTest
{
	[6] = 600;
	[7] = 700;
	[8] = 800;
	[9] = 900;
	[10] = 1000;

	[1] = 100;
	[2] = 200;
	[3] = 300;
	[4] = 400;
	[5] = 500;
}

instance <- CTest()

Print using

foreach( k, v in instance.getclass() ) printl( k + " : " + instance[k] )

Before save, expected

1 : 100
2 : 200
3 : 300
4 : 400
5 : 500

6 : 600
7 : 700
8 : 800
9 : 900
10 : 1000

After load, values are incorrectly assigned

1 : 600
2 : 700
3 : 800
4 : 900
5 : 1000

6 : 100
7 : 200
8 : 300
9 : 400
10 : 500

This does not happen when class members are declared in (hash) order

class CTest
{
	[1] = 100;
	[2] = 200;
	[3] = 300;
	[4] = 400;
	[5] = 500;

	[6] = 600;
	[7] = 700;
	[8] = 800;
	[9] = 900;
	[10] = 1000;
}

Additional context

The issue comes from SquirrelVM writing class members using hash iterator (SQClass::Next) while class instance loads members by iterating SQClass::_defaultvalues which is ordered by member declaration order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingVScriptMapbase - Involves VScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions