MTROPOLIS: add fallback palette to MovieElement blitting (#5811)

* MTROPOLIS: add fallback palette to MovieElement blitting

Without a palette, there would be assertions and nullptr segfaults
in Graphics::ManagedSurface::blitFromInner.
Observed in MindGym and The Day The World Broke

The palette content is not correct yet. Mind Gym renders the video
with the wrong colors.

* MTROPOLIS: use global palette as fallback for MovieElement
This commit is contained in:
meekee7 2024-07-03 20:54:47 +02:00 committed by GitHub
parent 209adeda68
commit 6777f200f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -781,7 +781,9 @@ void MovieElement::render(Window *window) {
Graphics::ManagedSurface *target = window->getSurface().get();
Common::Rect srcRect(0, 0, displaySurface->w, displaySurface->h);
Common::Rect destRect(_cachedAbsoluteOrigin.x, _cachedAbsoluteOrigin.y, _cachedAbsoluteOrigin.x + _rect.width(), _cachedAbsoluteOrigin.y + _rect.height());
target->blitFrom(*displaySurface, srcRect, destRect);
initFallbackPalette();
target->blitFrom(*displaySurface, srcRect, destRect, _fallbackPalette.get());
}
}
@ -963,6 +965,13 @@ void MovieElement::stopSubtitles() {
_subtitles->stop();
}
void MovieElement::initFallbackPalette() {
if (!_fallbackPalette) {
const Palette &globalPalette = getRuntime()->getGlobalPalette();
_fallbackPalette = Common::ScopedPtr<Graphics::Palette>(new Graphics::Palette(globalPalette.getPalette(), globalPalette.kNumColors));
}
}
void MovieElement::onPauseStateChanged() {
VisualElement::onPauseStateChanged();

View File

@ -23,6 +23,7 @@
#define MTROPOLIS_ELEMENTS_H
#include "graphics/fontman.h"
#include "graphics/palette.h"
#include "mtropolis/data.h"
#include "mtropolis/runtime.h"
@ -120,6 +121,8 @@ private:
void stopSubtitles();
void initFallbackPalette();
MiniscriptInstructionOutcome scriptSetRange(MiniscriptThread *thread, const DynamicValue &value);
MiniscriptInstructionOutcome scriptSetRangeStart(MiniscriptThread *thread, const DynamicValue &value);
MiniscriptInstructionOutcome scriptSetRangeEnd(MiniscriptThread *thread, const DynamicValue &value);
@ -173,6 +176,8 @@ private:
Common::SharedPtr<SubtitlePlayer> _subtitles;
Common::Array<int> _damagedFrames;
Common::ScopedPtr<Graphics::Palette> _fallbackPalette;
};
class ImageElement : public VisualElement {