mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
fix(tracker): unmarshal always into fresh, empty structs
A somewhat gotcha: when unmarshaling into &m.d with json.Unmarshal or yaml.Unmarshal, maps were "merged" with the existing maps, which is how we ended up with send units with color parameters, among other things. This fix always unmarshals into fresh var data modelData and only then sets m.d = data if the unmarshaling was succesful.
This commit is contained in:
parent
19661f90ea
commit
9d59cfb3b6
@ -193,7 +193,10 @@ func NewModelPlayer(broker *Broker, synther sointu.Synther, midiContext MIDICont
|
||||
m.resetSong()
|
||||
if recoveryFilePath != "" {
|
||||
if bytes2, err := os.ReadFile(m.d.RecoveryFilePath); err == nil {
|
||||
json.Unmarshal(bytes2, &m.d)
|
||||
var data modelData
|
||||
if json.Unmarshal(bytes2, &data) == nil {
|
||||
m.d = data
|
||||
}
|
||||
}
|
||||
}
|
||||
m.signalAnalyzer = NewScopeModel(broker, m.d.Song.BPM)
|
||||
@ -326,13 +329,18 @@ func (m *Model) SaveRecovery() error {
|
||||
}
|
||||
|
||||
func (m *Model) UnmarshalRecovery(bytes []byte) {
|
||||
err := json.Unmarshal(bytes, &m.d)
|
||||
var data modelData
|
||||
err := json.Unmarshal(bytes, &data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
m.d = data
|
||||
if m.d.RecoveryFilePath != "" { // check if there's a recovery file on disk and load it instead
|
||||
if bytes2, err := os.ReadFile(m.d.RecoveryFilePath); err == nil {
|
||||
json.Unmarshal(bytes2, &m.d)
|
||||
var data modelData
|
||||
if json.Unmarshal(bytes2, &data) == nil {
|
||||
m.d = data
|
||||
}
|
||||
}
|
||||
}
|
||||
m.d.ChangedSinceRecovery = false
|
||||
|
Loading…
Reference in New Issue
Block a user