Open IaVashik opened 2 months ago
I don't quite understand why this issue was moved to this repository, which is specifically related to the Linux native port, as I understand it. It seems that the Source-1-Games repository would be a more appropriate place for this problem, considering the nature of the issue. Could you please clarify the reasoning behind this decision?
Hello @IaVashik, this issue tracker is more likely to be viewed by the Valve dev(s) that maintain Portal 2 than the Source-1-Games issue tracker.
Hello @IaVashik, this issue tracker is more likely to be viewed by the Valve dev(s) that maintain Portal 2 than the Source-1-Games issue tracker.
This is a little confusing to me, due to the repository description, but I get it. Thanks for the quick response!
Description:
Unusual using classes in VSquirrel 2+ for Portal 2 modding can lead to critical save/load failures, effectively breaking the game. Several specific scenarios involving class interactions consistently trigger these issues.
Problem 1: Inheritance
Even simple inheritance can cause Portal 2 to crash on save/load.
Example:
While the inheritance mechanism itself works during runtime, attempting to load a saved game state containing these classes results in a crash.
Problem 2: Circular References Within Classes
Mutual references between class instances, even when using weakref, can still lead to crashes during save/load or cause the VSquirrel VM to break down. This is likely due to how references are handled during the serialization process, which fails to properly account for these circular dependencies.
Example:
This results in errors like:
Problem 3: Free Variables Within Class Methods
Using free variables within class methods in specific ways, particularly when they reference the class instance itself, can also lead to save/load errors.
Example:
Final Notes and Workarounds:
I understand that classes in VScripts are not widely used in Portal 2 modding, and therefore, these issues might not be prioritized for fixing, which is completely reasonable. However, I'd like to offer some workarounds for those who do encounter these issues:
Inheritance: Instead of using inheritance, consider using composition or replacing the class with a table and a
clone
method for creating copies.Mutual References: Use a table with delegation:
Or implement a global storage system, as in this example:
Free Variables: Avoid using free variables in this particular way.
Radical Solution: Disable saving entirely with
map_wants_save_disable 1
, and you won’t have to deal with these issues! :D