Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts do not convert while serializing for saving simulations #3815

Closed
LorisHenry opened this issue May 18, 2023 · 4 comments
Closed

Fonts do not convert while serializing for saving simulations #3815

LorisHenry opened this issue May 18, 2023 · 4 comments
Assignees
Labels
😱 Bug The issue reveals a bug in GAMA 👍 Fix to be tested
Milestone

Comments

@LorisHenry
Copy link

Describe the bug
Fonts do not convert while serializing for saving simulations. Can not convert fonts, raises exception

/**
* Name: ModelSaveAndSerialize
* Author: Benoit Gaudou
* Description: Save a simulation to a file and display the serialization of the simulation
* Tags: serialization, save_file
*/

model ModelSaveAndSerialize

global {
	int toot <- 0;
	string s <- "test";
	
	
	
	
	
	////
	font ui_font <- font('Helvetica Neue',12, #bold);
	////
	
	
	
	
	
	init {
		create people number: 1;
	}
}

species people {
	int t;
	list<int> lo <- [1,2,3];
}

experiment SaveSimulation type: gui {
	
	reflex save_simulation when: cycle mod 2 = 0 {
		write "================ START SAVE + self " + " - " + cycle ;		
		write "Save of simulation : " + save_simulation('../result/file.gsim');
		// alternative to save_simulation : 		save saved_simulation_file('../result/file.gsim', [simulation]);
		write "================ END SAVE + self " + " - " + cycle ;					
	}
	
	reflex serialize_agent when: cycle mod 2 = 1 {
		write "================ Serialize simulation " + self + " - " + cycle;
		write serialize_agent(self.simulation);
		write "================ END Serialize simulation " + self + " - " + cycle;				
	}
	
}


@AlexisDrogoul
Copy link
Member

The converter for GamaFont is effectively missing. Should be added to the bugfix release !

@AlexisDrogoul AlexisDrogoul added the 😱 Bug The issue reveals a bug in GAMA label May 21, 2023
@AlexisDrogoul AlexisDrogoul self-assigned this May 21, 2023
@AlexisDrogoul AlexisDrogoul added this to the GAMA 1.9.2 milestone May 21, 2023
AlexisDrogoul added a commit that referenced this issue May 22, 2023
@lesquoyb
Copy link
Collaborator

The serialisation works, but seems like deserialisation is broken now, if you add this experiment to the file:

experiment load type:gui {
	action _init_ {
		create simulation from: saved_simulation_file("../result/file.gsim");	
		write "init simulation at step " + simulation.cycle;
	}
}

You will realise that it raises an exception while trying to load:

1 occurence in load0 at cycle 0: Java error: ConversionException
in load0
in create simulation from: saved_simulation_file('../result/file.gsim') ;
ConversionException: 
---- Debugging information ----
cause-exception     : java.lang.UnsupportedOperationException
cause-message       : can't get field offset on a record class: private final float ummisco.gama.serializer.gamaType.converters.GamaColorConverter$GamaColorRecord.r
class               : ummisco.gama.serializer.gamaType.converters.GamaColorConverter$GamaColorRecord
required-type       : ummisco.gama.serializer.gamaType.converters.GamaColorConverter$GamaColorRecord
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /msi.gama.metamodel.agent.SavedAgent/variables/data/msi.gama.util.GamaColor/r
class[1]            : msi.gama.util.GamaColor
required-type[1]    : msi.gama.util.GamaColor
converter-type[1]   : ummisco.gama.serializer.gamaType.converters.GamaColorConverter
class[2]            : java.util.ArrayList
required-type[2]    : java.util.ArrayList
converter-type[2]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[3]            : msi.gama.metamodel.agent.SavedAgent
required-type[3]    : msi.gama.metamodel.agent.SavedAgent
converter-type[3]   : ummisco.gama.serializer.gamaType.converters.SavedAgentConverter
version             : 1.4.18
-------------------------------
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:77)
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
ummisco.gama.serializer.gamaType.converters.GamaColorConverter.read(GamaColorConverter.java:74)
ummisco.gama.serializer.gamaType.converters.GamaColorConverter.read(GamaColorConverter.java:1)
ummisco.gama.serializer.gamaType.converters.IGamaConverter.unmarshal(IGamaConverter.java:45)
in agent load0

The content of the file is normal (doesn't seem malformed) but to me color serialisation/deserialisation used to work properly before so it may be a consequence of this commit

@lesquoyb
Copy link
Collaborator

The proposed workaround didn't fix the issue, the error stack is still the same (UnsupportedOperationException, can't get field offset on a record class: private final float ummisco.gama.serializer.gamaType.converters.GamaColorConverter$GamaColorRecord.r )

@AlexisDrogoul
Copy link
Member

OK. I see where it is coming from... I've pushed a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😱 Bug The issue reveals a bug in GAMA 👍 Fix to be tested
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants