Skip to content

Commit

Permalink
Merge pull request #1355 from Lazin3ss/development
Browse files Browse the repository at this point in the history
fix: corrupted sounds freezing the game, ignorehitpause not affecting "else" statement in ZSS
  • Loading branch information
K4thos committed Aug 3, 2023
2 parents a1e0741 + 0e867b7 commit 476b91f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4652,7 +4652,7 @@ func (c *Compiler) subBlock(line *string, root bool,
c.scan(line)
var err error
if bl.elseBlock, err = c.subBlock(line, root,
sbc, numVars, inheritIhp, nestedInLoop); err != nil {
sbc, numVars, inheritIhp || bl.ctrlsIgnorehitpause, nestedInLoop); err != nil {
return nil, err
}
if bl.elseBlock.ignorehitpause >= -1 {
Expand Down
16 changes: 16 additions & 0 deletions src/sound.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ func readSound(f *os.File, size uint32) (*Sound, error) {
if err != nil {
return nil, err
}
// Check if the file can be fully played
var samples [512][2]float64
for {
sn, _ := s.Stream(samples[:])
if sn == 0 {
// If sound wasn't able to be fully played, we disable it to avoid engine freezing
if s.Position() < s.Len() {
return nil, nil
}
break;
}
}
return &Sound{wavData, fmt, s.Len()}, nil
}

Expand Down Expand Up @@ -372,6 +384,10 @@ func LoadSndFiltered(filename string, keepItem func([2]int32) bool, max uint32)
return nil, err
}
} else {
// Sound is corrupted and can't be played, so we export a warning message to the console
if tmp == nil {
sys.appendToConsole(fmt.Sprintf("WARNING: %v sound %v,%v is corrupted and can't be played, so it was disabled", filename, num[0], num[1]))
}
s.table[num] = tmp
if max > 0 {
break
Expand Down

0 comments on commit 476b91f

Please sign in to comment.