SCI: Fix SoundResource error handling, ctor, dtor
Fixes several problems with the SoundResource class: - Constructor doesn't fully initialize object if resource doesn't exist - Destructor crashes if object not fully initialized - Constructor has no mechanism to report failure - Callers believe failure is reported by constructor returning null - SoundCommandParser::initSoundResource attempts to pre-detect failure insufficiently in the absence of a formal mechanism. SoundResource now always fully initializes, the destructor no longer accesses uninitialized memory, and an exists() method has been added which callers now test. SQ6 Mac can now progress past the main menu.
This commit is contained in:
parent
17611ac289
commit
23fc7f52e0
5 changed files with 43 additions and 40 deletions
|
@ -2705,24 +2705,22 @@ bool Console::cmdIsSample(int argc, const char **argv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
SoundResource *soundRes = new SoundResource(number, _engine->getResMan(), _engine->_features->detectDoSoundType());
|
||||
SoundResource soundRes(number, _engine->getResMan(), _engine->_features->detectDoSoundType());
|
||||
|
||||
if (!soundRes) {
|
||||
if (!soundRes.exists()) {
|
||||
debugPrintf("Not a sound resource!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
SoundResource::Track *track = soundRes->getDigitalTrack();
|
||||
SoundResource::Track *track = soundRes.getDigitalTrack();
|
||||
if (!track || track->digitalChannelNr == -1) {
|
||||
debugPrintf("Valid song, but not a sample.\n");
|
||||
delete soundRes;
|
||||
return true;
|
||||
}
|
||||
|
||||
debugPrintf("Sample size: %d, sample rate: %d, channels: %d, digital channel number: %d\n",
|
||||
track->digitalSampleSize, track->digitalSampleRate, track->channelCount, track->digitalChannelNr);
|
||||
|
||||
delete soundRes;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue