[Scummvm-git-logs] scummvm master -> 1289b71437805da275d687bfcbdec33a0078ebba
phcoder
noreply at scummvm.org
Thu Jan 19 16:29:45 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
1289b71437 NEVERHOOD: Fix crash on expiring surfaces.
Commit: 1289b71437805da275d687bfcbdec33a0078ebba
https://github.com/scummvm/scummvm/commit/1289b71437805da275d687bfcbdec33a0078ebba
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2023-01-19T19:29:40+03:00
Commit Message:
NEVERHOOD: Fix crash on expiring surfaces.
We postpone actual drawing until the frame finishes. At this point some of
the surfaces might have been freed and the pointers are no longer valid.
Use reference counting to ensure that queue surfaces are still valid
Thanks to -=CHE at TER=- for reporting and providing the triggering save
and instructions.
Changed paths:
engines/neverhood/background.cpp
engines/neverhood/background.h
engines/neverhood/graphics.cpp
engines/neverhood/graphics.h
engines/neverhood/menumodule.cpp
engines/neverhood/menumodule.h
engines/neverhood/modules/module2700_sprites.cpp
engines/neverhood/modules/module2700_sprites.h
engines/neverhood/modules/module2800_sprites.cpp
engines/neverhood/scene.cpp
engines/neverhood/scene.h
engines/neverhood/smackerplayer.cpp
engines/neverhood/smackerplayer.h
engines/neverhood/sprite.cpp
engines/neverhood/sprite.h
diff --git a/engines/neverhood/background.cpp b/engines/neverhood/background.cpp
index 21cf8227fba..846748368f2 100644
--- a/engines/neverhood/background.cpp
+++ b/engines/neverhood/background.cpp
@@ -39,12 +39,8 @@ Background::Background(NeverhoodEngine *vm, uint32 fileHash, int objectPriority,
}
-Background::~Background() {
- delete _surface;
-}
-
void Background::createSurface(int surfacePriority, int16 width, int16 height) {
- _surface = new BaseSurface(_vm, surfacePriority, width, height, "background");
+ _surface .reset(new BaseSurface(_vm, surfacePriority, width, height, "background"));
_surface->setTransparent(false);
_spriteResource.getPosition().x = width;
_spriteResource.getPosition().y = height;
diff --git a/engines/neverhood/background.h b/engines/neverhood/background.h
index d13454f5429..938314eb820 100644
--- a/engines/neverhood/background.h
+++ b/engines/neverhood/background.h
@@ -33,13 +33,12 @@ class Background : public Entity {
public:
Background(NeverhoodEngine *vm, int objectPriority);
Background(NeverhoodEngine *vm, uint32 fileHash, int objectPriority, int surfacePriority);
- ~Background() override;
- BaseSurface *getSurface() { return _surface; }
+ Common::SharedPtr<BaseSurface> getSurface() { return _surface; }
void createSurface(int surfacePriority, int16 width, int16 height);
void load(uint32 fileHash);
SpriteResource& getSpriteResource() { return _spriteResource; }
protected:
- BaseSurface *_surface;
+ Common::SharedPtr<BaseSurface> _surface;
SpriteResource _spriteResource;
};
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp
index 5fda85f155c..cdf91b8dddf 100644
--- a/engines/neverhood/graphics.cpp
+++ b/engines/neverhood/graphics.cpp
@@ -137,7 +137,7 @@ void BaseSurface::copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, N
// ShadowSurface
-ShadowSurface::ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, BaseSurface *shadowSurface)
+ ShadowSurface::ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, const Common::SharedPtr<BaseSurface> &shadowSurface)
: BaseSurface(vm, priority, width, height, "shadow"), _shadowSurface(shadowSurface) {
// Empty
}
@@ -182,13 +182,14 @@ void FontSurface::drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr)
destSurface->copyFrom(_surface, x, y, sourceRect);
}
-void FontSurface::drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen) {
+void FontSurface::drawString(const Common::SharedPtr<BaseSurface> &destSurface, int16 x, int16 y, const byte *string, int stringLen) {
+ BaseSurface *destSurfaceRaw = destSurface.get();
if (stringLen < 0)
stringLen = strlen((const char*)string);
for (; stringLen > 0; --stringLen, ++string) {
- drawChar(destSurface, x, y, *string);
+ drawChar(destSurfaceRaw, x, y, *string);
x += _tracking ? (*_tracking)[*string - _firstChar].x : _charWidth;
}
diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h
index 0566c5e0d98..759ae929059 100644
--- a/engines/neverhood/graphics.h
+++ b/engines/neverhood/graphics.h
@@ -124,10 +124,10 @@ protected:
class ShadowSurface : public BaseSurface {
public:
- ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, BaseSurface *shadowSurface);
+ ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, const Common::SharedPtr<BaseSurface> &shadowSurface);
void draw() override;
protected:
- BaseSurface *_shadowSurface;
+ Common::SharedPtr<BaseSurface> _shadowSurface;
};
class FontSurface : public BaseSurface {
@@ -136,7 +136,7 @@ public:
FontSurface(NeverhoodEngine *vm, uint32 fileHash, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight);
~FontSurface() override;
void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr);
- void drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen = -1);
+ void drawString(const Common::SharedPtr<BaseSurface> &destSurface, int16 x, int16 y, const byte *string, int stringLen = -1);
int16 getStringWidth(const byte *string, int stringLen);
uint16 getCharWidth() const { return _charWidth; }
uint16 getCharHeight() const { return _charHeight; }
diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp
index ca53b260c02..5aa187fea81 100644
--- a/engines/neverhood/menumodule.cpp
+++ b/engines/neverhood/menumodule.cpp
@@ -577,7 +577,7 @@ uint32 Widget::handleMessage(int messageNum, const MessageParam ¶m, Entity *
TextLabelWidget::TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
int baseObjectPriority, int baseSurfacePriority,
- const byte *string, int stringLen, BaseSurface *drawSurface, int16 tx, int16 ty, FontSurface *fontSurface)
+ const byte *string, int stringLen, const Common::SharedPtr<BaseSurface> &drawSurface, int16 tx, int16 ty, const Common::SharedPtr<FontSurface> &fontSurface)
: Widget(vm, x, y, parentScene, baseObjectPriority, baseSurfacePriority),
_string(string), _stringLen(stringLen), _drawSurface(drawSurface), _tx(tx), _ty(ty), _fontSurface(fontSurface) {
@@ -613,7 +613,7 @@ void TextLabelWidget::setString(const byte *string, int stringLen) {
}
TextEditWidget::TextEditWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
- int maxStringLength, FontSurface *fontSurface, uint32 fileHash, const NRect &rect)
+ int maxStringLength, const Common::SharedPtr<FontSurface> &fontSurface, uint32 fileHash, const NRect &rect)
: Widget(vm, x, y, parentScene, 1000, 1000),
_maxStringLength(maxStringLength), _fontSurface(fontSurface), _fileHash(fileHash), _rect(rect),
_cursorSurface(nullptr), _cursorTicks(0), _cursorPos(0), _cursorFileHash(0), _cursorWidth(0), _cursorHeight(0),
@@ -803,7 +803,7 @@ uint32 TextEditWidget::handleMessage(int messageNum, const MessageParam ¶m,
}
SavegameListBox::SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
- SavegameList *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect)
+ SavegameList *savegameList, const Common::SharedPtr<FontSurface> &fontSurface, uint32 bgFileHash, const NRect &rect)
: Widget(vm, x, y, parentScene, 1000, 1000),
_savegameList(savegameList), _fontSurface(fontSurface), _bgFileHash(bgFileHash), _rect(rect),
_maxStringLength(0), _firstVisibleItem(0), _lastVisibleItem(0), _currIndex(0) {
@@ -944,7 +944,7 @@ GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, Savegame
bool isSave = (textEditCursorFileHash != 0);
- _fontSurface = new FontSurface(_vm, fontFileHash, 32, 7, 32, 11, 17);
+ _fontSurface.reset(new FontSurface(_vm, fontFileHash, 32, 7, 32, 11, 17));
if (!ConfMan.getBool("originalsaveload")) {
Common::String saveDesc;
@@ -994,10 +994,6 @@ GameStateMenu::GameStateMenu(NeverhoodEngine *vm, Module *parentModule, Savegame
SetMessageHandler(&GameStateMenu::handleMessage);
}
-GameStateMenu::~GameStateMenu() {
- delete _fontSurface;
-}
-
NPoint GameStateMenu::getMousePos() {
NPoint pt;
pt.x = _mouseCursor->getX();
diff --git a/engines/neverhood/menumodule.h b/engines/neverhood/menumodule.h
index aa2a8e56cbd..cda2e9b1611 100644
--- a/engines/neverhood/menumodule.h
+++ b/engines/neverhood/menumodule.h
@@ -123,19 +123,19 @@ protected:
class TextLabelWidget : public Widget {
public:
TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
- int baseObjectPriority, int baseSurfacePriority,
- const byte *string, int stringLen, BaseSurface *drawSurface, int16 tx, int16 ty, FontSurface *fontSurface);
+ int baseObjectPriority, int baseSurfacePriority,
+ const byte *string, int stringLen, const Common::SharedPtr<BaseSurface> &drawSurface, int16 tx, int16 ty, const Common::SharedPtr<FontSurface> &fontSurface);
void initialize() override;
int16 getWidth() override;
int16 getHeight() override;
void drawString(int maxStringLength);
void clear();
void setString(const byte *string, int stringLen);
- FontSurface *getFontSurface() const { return _fontSurface; }
+ Common::SharedPtr<FontSurface> getFontSurface() const { return _fontSurface; }
protected:
- BaseSurface *_drawSurface;
+ Common::SharedPtr<BaseSurface> _drawSurface;
int16 _tx, _ty;
- FontSurface *_fontSurface;
+ Common::SharedPtr<FontSurface> _fontSurface;
const byte *_string;
int _stringLen;
};
@@ -143,7 +143,7 @@ protected:
class TextEditWidget : public Widget {
public:
TextEditWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
- int maxStringLength, FontSurface *fontSurface, uint32 fileHash, const NRect &rect);
+ int maxStringLength, const Common::SharedPtr<FontSurface> &fontSurface, uint32 fileHash, const NRect &rect);
~TextEditWidget() override;
void onClick() override;
void initialize() override;
@@ -168,7 +168,7 @@ protected:
int _cursorPos;
int _cursorTicks;
Common::String _entryString;
- FontSurface *_fontSurface;
+ Common::SharedPtr<FontSurface> _fontSurface;
TextLabelWidget *_textLabelWidget;
BaseSurface *_cursorSurface;
uint32 _cursorFileHash;
@@ -182,7 +182,7 @@ protected:
class SavegameListBox : public Widget {
public:
SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
- SavegameList *savegameList, FontSurface *fontSurface, uint32 bgFileHash, const NRect &rect);
+ SavegameList *savegameList, const Common::SharedPtr<FontSurface> &fontSurface, uint32 bgFileHash, const NRect &rect);
void onClick() override;
void initialize() override;
void buildItems();
@@ -201,7 +201,7 @@ protected:
int _firstVisibleItem;
int _lastVisibleItem;
SavegameList *_savegameList;
- FontSurface *_fontSurface;
+ Common::SharedPtr<FontSurface> _fontSurface;
uint _currIndex;
int _maxVisibleItemsCount;
};
@@ -215,7 +215,6 @@ public:
uint32 listBoxBackgroundFileHash, int16 listBoxX, int16 listBoxY, const NRect &listBoxRect,
uint32 textEditBackgroundFileHash, uint32 textEditCursorFileHash, int16 textEditX, int16 textEditY, const NRect &textEditRect,
uint32 textFileHash1, uint32 textFileHash2);
- ~GameStateMenu() override;
NPoint getMousePos();
virtual void setCurrWidget(Widget *newWidget);
virtual Widget *getCurrWidget() { return _currWidget; }
@@ -223,7 +222,7 @@ public:
protected:
Widget *_currWidget;
SavegameList *_savegameList;
- FontSurface *_fontSurface;
+ Common::SharedPtr<FontSurface> _fontSurface;
SavegameListBox *_listBox;
TextEditWidget *_textEditWidget;
Common::String _savegameDescription;
diff --git a/engines/neverhood/modules/module2700_sprites.cpp b/engines/neverhood/modules/module2700_sprites.cpp
index 52134340b0f..bb5d0566f5b 100644
--- a/engines/neverhood/modules/module2700_sprites.cpp
+++ b/engines/neverhood/modules/module2700_sprites.cpp
@@ -36,7 +36,7 @@ SsCommonTrackShadowBackground::SsCommonTrackShadowBackground(NeverhoodEngine *vm
loadSprite(fileHash, kSLFDefDrawOffset | kSLFDefPosition, 0);
}
-AsCommonCarShadow::AsCommonCarShadow(NeverhoodEngine *vm, AnimatedSprite *asCar, BaseSurface *shadowSurface, uint index)
+AsCommonCarShadow::AsCommonCarShadow(NeverhoodEngine *vm, AnimatedSprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, uint index)
: AnimatedSprite(vm, 1100), _asCar(asCar), _index(index), _animFileHash(0) {
SetUpdateHandler(&AsCommonCarShadow::update);
@@ -70,7 +70,7 @@ void AsCommonCarShadow::updateShadow() {
setDoDeltaX(_asCar->isDoDeltaX() ? 1 : 0);
}
-AsCommonCarConnectorShadow::AsCommonCarConnectorShadow(NeverhoodEngine *vm, Sprite *asCar, BaseSurface *shadowSurface, uint index)
+AsCommonCarConnectorShadow::AsCommonCarConnectorShadow(NeverhoodEngine *vm, Sprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, uint index)
: AnimatedSprite(vm, 1100), _asCar(asCar), _index(index) {
SetUpdateHandler(&AsCommonCarConnectorShadow::update);
@@ -85,7 +85,7 @@ void AsCommonCarConnectorShadow::update() {
AnimatedSprite::update();
}
-AsCommonCarTrackShadow::AsCommonCarTrackShadow(NeverhoodEngine *vm, Sprite *asCar, BaseSurface *shadowSurface, int16 frameIndex)
+AsCommonCarTrackShadow::AsCommonCarTrackShadow(NeverhoodEngine *vm, Sprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, int16 frameIndex)
: AnimatedSprite(vm, 1100), _asCar(asCar) {
SetUpdateHandler(&AsCommonCarTrackShadow::update);
diff --git a/engines/neverhood/modules/module2700_sprites.h b/engines/neverhood/modules/module2700_sprites.h
index 05acf1e4df2..f16601765b8 100644
--- a/engines/neverhood/modules/module2700_sprites.h
+++ b/engines/neverhood/modules/module2700_sprites.h
@@ -35,7 +35,7 @@ public:
class AsCommonCarShadow : public AnimatedSprite {
public:
- AsCommonCarShadow(NeverhoodEngine *vm, AnimatedSprite *asCar, BaseSurface *shadowSurface, uint index);
+ AsCommonCarShadow(NeverhoodEngine *vm, AnimatedSprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, uint index);
protected:
uint _index;
AnimatedSprite *_asCar;
@@ -46,7 +46,7 @@ protected:
class AsCommonCarConnectorShadow : public AnimatedSprite {
public:
- AsCommonCarConnectorShadow(NeverhoodEngine *vm, Sprite *asCar, BaseSurface *shadowSurface, uint index);
+ AsCommonCarConnectorShadow(NeverhoodEngine *vm, Sprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, uint index);
protected:
uint _index;
Sprite *_asCar;
@@ -55,7 +55,7 @@ protected:
class AsCommonCarTrackShadow : public AnimatedSprite {
public:
- AsCommonCarTrackShadow(NeverhoodEngine *vm, Sprite *asCar, BaseSurface *shadowSurface, int16 frameIndex);
+ AsCommonCarTrackShadow(NeverhoodEngine *vm, Sprite *asCar, const Common::SharedPtr<BaseSurface> &shadowSurface, int16 frameIndex);
protected:
Sprite *_asCar;
void update();
diff --git a/engines/neverhood/modules/module2800_sprites.cpp b/engines/neverhood/modules/module2800_sprites.cpp
index 11d6f7c42c8..4997ff299fb 100644
--- a/engines/neverhood/modules/module2800_sprites.cpp
+++ b/engines/neverhood/modules/module2800_sprites.cpp
@@ -1329,7 +1329,6 @@ KmScene2806::KmScene2806(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16
if (needsLargeSurface) {
NDimensions dimensions = _animResource.loadSpriteDimensions(0x2838C010);
- delete _surface;
createSurface(1000, dimensions.width, dimensions.height);
loadSound(3, 0x58E0C341);
loadSound(4, 0x40A00342);
@@ -1389,7 +1388,6 @@ KmScene2809::KmScene2809(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16
if (needsLargeSurface) {
NDimensions dimensions = _animResource.loadSpriteDimensions(0x2838C010);
- delete _surface;
createSurface(1000, dimensions.width, dimensions.height);
loadSound(3, 0x58E0C341);
loadSound(4, 0x40A00342);
diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp
index d79f1187572..ecfb63ab03e 100644
--- a/engines/neverhood/scene.cpp
+++ b/engines/neverhood/scene.cpp
@@ -87,7 +87,7 @@ void Scene::draw() {
if (_smackerPlayer->getSurface())
_smackerPlayer->getSurface()->draw();
} else {
- for (Common::Array<BaseSurface*>::iterator iter = _surfaces.begin(); iter != _surfaces.end(); iter++)
+ for (Common::Array<Common::SharedPtr<BaseSurface>>::iterator iter = _surfaces.begin(); iter != _surfaces.end(); iter++)
(*iter)->draw();
}
}
@@ -116,10 +116,10 @@ bool Scene::removeEntity(Entity *entity) {
return false;
}
-void Scene::addSurface(BaseSurface *surface) {
+void Scene::addSurface(const Common::SharedPtr<BaseSurface> &surface) {
if (surface) {
int index = 0, insertIndex = -1;
- for (Common::Array<BaseSurface*>::iterator iter = _surfaces.begin(); iter != _surfaces.end(); iter++) {
+ for (Common::Array<Common::SharedPtr<BaseSurface>>::iterator iter = _surfaces.begin(); iter != _surfaces.end(); iter++) {
if ((*iter)->getPriority() > surface->getPriority()) {
insertIndex = index;
break;
@@ -133,9 +133,9 @@ void Scene::addSurface(BaseSurface *surface) {
}
}
-bool Scene::removeSurface(BaseSurface *surface) {
+bool Scene::removeSurface(const Common::SharedPtr<BaseSurface> &surface) {
for (uint index = 0; index < _surfaces.size(); index++) {
- if (_surfaces[index] == surface) {
+ if (_surfaces[index].get() == surface.get()) {
_surfaces.remove_at(index);
return true;
}
@@ -167,7 +167,7 @@ void Scene::removeSprite(Sprite *sprite) {
removeEntity(sprite);
}
-void Scene::setSurfacePriority(BaseSurface *surface, int priority) {
+void Scene::setSurfacePriority(const Common::SharedPtr<BaseSurface> &surface, int priority) {
surface->setPriority(priority);
if (removeSurface(surface))
addSurface(surface);
diff --git a/engines/neverhood/scene.h b/engines/neverhood/scene.h
index 50e65ed69d4..fea767f4dc1 100644
--- a/engines/neverhood/scene.h
+++ b/engines/neverhood/scene.h
@@ -45,12 +45,12 @@ public:
void draw() override;
void addEntity(Entity *entity);
bool removeEntity(Entity *entity);
- void addSurface(BaseSurface *surface);
- bool removeSurface(BaseSurface *surface);
+ void addSurface(const Common::SharedPtr<BaseSurface> &surface);
+ bool removeSurface(const Common::SharedPtr<BaseSurface> &surface);
void printSurfaces(Console *con);
Sprite *addSprite(Sprite *sprite);
void removeSprite(Sprite *sprite);
- void setSurfacePriority(BaseSurface *surface, int priority);
+ void setSurfacePriority(const Common::SharedPtr<BaseSurface> &surface, int priority);
void setSpriteSurfacePriority(Sprite *sprite, int priority);
void deleteSprite(Sprite **sprite);
Background *addBackground(Background *background);
@@ -168,7 +168,7 @@ public:
protected:
Module *_parentModule;
Common::Array<Entity*> _entities;
- Common::Array<BaseSurface*> _surfaces;
+ Common::Array<Common::SharedPtr<BaseSurface>> _surfaces;
Klaymen *_klaymen;
Background *_background;
diff --git a/engines/neverhood/smackerplayer.cpp b/engines/neverhood/smackerplayer.cpp
index a992e8514de..c1e92b1e9ed 100644
--- a/engines/neverhood/smackerplayer.cpp
+++ b/engines/neverhood/smackerplayer.cpp
@@ -152,9 +152,9 @@ SmackerPlayer::SmackerPlayer(NeverhoodEngine *vm, Scene *scene, uint32 fileHash,
SetUpdateHandler(&SmackerPlayer::update);
if (_doubleSurface) {
- _smackerSurface = new SmackerDoubleSurface(_vm);
+ _smackerSurface.reset(new SmackerDoubleSurface(_vm));
} else {
- _smackerSurface = new SmackerSurface(_vm);
+ _smackerSurface.reset(new SmackerSurface(_vm));
}
open(fileHash, flag);
@@ -162,8 +162,7 @@ SmackerPlayer::SmackerPlayer(NeverhoodEngine *vm, Scene *scene, uint32 fileHash,
SmackerPlayer::~SmackerPlayer() {
close();
- delete _smackerSurface;
- _smackerSurface = nullptr;
+ _smackerSurface.reset();
}
void SmackerPlayer::open(uint32 fileHash, bool keepLastFrame) {
diff --git a/engines/neverhood/smackerplayer.h b/engines/neverhood/smackerplayer.h
index 24dd4e7c8bd..8eaf854bfa4 100644
--- a/engines/neverhood/smackerplayer.h
+++ b/engines/neverhood/smackerplayer.h
@@ -62,7 +62,7 @@ class SmackerPlayer : public Entity {
public:
SmackerPlayer(NeverhoodEngine *vm, Scene *scene, uint32 fileHash, bool doubleSurface, bool flag, bool paused = false);
~SmackerPlayer() override;
- BaseSurface *getSurface() { return _smackerSurface; }
+ Common::SharedPtr<BaseSurface> getSurface() { return _smackerSurface; }
void open(uint32 fileHash, bool keepLastFrame);
void close();
void gotoFrame(int frameNumber);
@@ -77,7 +77,7 @@ protected:
Scene *_scene;
Palette *_palette;
NeverhoodSmackerDecoder *_smackerDecoder;
- SmackerSurface *_smackerSurface;
+ Common::SharedPtr<SmackerSurface> _smackerSurface;
uint32 _fileHash;
bool _smackerFirst;
bool _doubleSurface;
diff --git a/engines/neverhood/sprite.cpp b/engines/neverhood/sprite.cpp
index 4f36dd0fa81..8cc058c47be 100644
--- a/engines/neverhood/sprite.cpp
+++ b/engines/neverhood/sprite.cpp
@@ -46,10 +46,6 @@ Sprite::Sprite(NeverhoodEngine *vm, int objectPriority)
SetMessageHandler(&Sprite::handleMessage);
}
-Sprite::~Sprite() {
- delete _surface;
-}
-
void Sprite::updateBounds() {
if (_doDeltaX) {
_collisionBounds.x1 = _x - _collisionBoundsOffset.x - _collisionBoundsOffset.width + 1;
@@ -94,7 +90,7 @@ void Sprite::loadDataResource(uint32 fileHash) {
}
void Sprite::createSurface(int surfacePriority, int16 width, int16 height) {
- _surface = new BaseSurface(_vm, surfacePriority, width, height, "sprite");
+ _surface.reset(new BaseSurface(_vm, surfacePriority, width, height, "sprite"));
}
int16 Sprite::defFilterY(int16 y) {
@@ -187,13 +183,13 @@ void StaticSprite::updatePosition() {
// AnimatedSprite
AnimatedSprite::AnimatedSprite(NeverhoodEngine *vm, int objectPriority)
- : Sprite(vm, objectPriority), _animResource(vm), _subtitleSurface(vm, this) {
+ : Sprite(vm, objectPriority), _animResource(vm), _subtitleSurface(new AnimatedSpriteSubtitles(vm, this)) {
init();
}
AnimatedSprite::AnimatedSprite(NeverhoodEngine *vm, uint32 fileHash, int surfacePriority, int16 x, int16 y)
- : Sprite(vm, 1100), _animResource(vm), _subtitleSurface(vm, this) {
+ : Sprite(vm, 1100), _animResource(vm), _subtitleSurface(new AnimatedSpriteSubtitles(vm, this)) {
init();
SetUpdateHandler(&AnimatedSprite::update);
@@ -372,10 +368,10 @@ void AnimatedSprite::updatePosition() {
}
int subCenterX = _surface->getDrawRect().x + _surface->getDrawRect().width / 2;
- _subtitleSurface.getDrawRect().x = MAX(subCenterX - kSubtitleWidth / 2, 0);
- _subtitleSurface.getDrawRect().width = kSubtitleWidth;
- _subtitleSurface.getDrawRect().y = MIN(_surface->getDrawRect().y + _surface->getDrawRect().height + 1, 480 - (SubtitlePlayer::kSubtitleCharHeight - 1));
- _subtitleSurface.getDrawRect().height = SubtitlePlayer::kSubtitleCharHeight;
+ _subtitleSurface->getDrawRect().x = MAX(subCenterX - kSubtitleWidth / 2, 0);
+ _subtitleSurface->getDrawRect().width = kSubtitleWidth;
+ _subtitleSurface->getDrawRect().y = MIN(_surface->getDrawRect().y + _surface->getDrawRect().height + 1, 480 - (SubtitlePlayer::kSubtitleCharHeight - 1));
+ _subtitleSurface->getDrawRect().height = SubtitlePlayer::kSubtitleCharHeight;
if (_needRefresh) {
_surface->drawAnimResource(_animResource, _currFrameIndex, _doDeltaX, _doDeltaY, _drawOffset.width, _drawOffset.height);
@@ -442,16 +438,16 @@ void AnimatedSprite::updateFrameInfo() {
void AnimatedSprite::createSurface1(uint32 fileHash, int surfacePriority) {
NDimensions dimensions = _animResource.loadSpriteDimensions(fileHash);
- _surface = new BaseSurface(_vm, surfacePriority, dimensions.width, dimensions.height, "animated sprite");
+ _surface.reset(new BaseSurface(_vm, surfacePriority, dimensions.width, dimensions.height, "animated sprite"));
}
-void AnimatedSprite::createShadowSurface1(BaseSurface *shadowSurface, uint32 fileHash, int surfacePriority) {
+void AnimatedSprite::createShadowSurface1(const Common::SharedPtr<BaseSurface> &shadowSurface, uint32 fileHash, int surfacePriority) {
NDimensions dimensions = _animResource.loadSpriteDimensions(fileHash);
- _surface = new ShadowSurface(_vm, surfacePriority, dimensions.width, dimensions.height, shadowSurface);
+ _surface.reset(new ShadowSurface(_vm, surfacePriority, dimensions.width, dimensions.height, shadowSurface));
}
-void AnimatedSprite::createShadowSurface(BaseSurface *shadowSurface, int16 width, int16 height, int surfacePriority) {
- _surface = new ShadowSurface(_vm, surfacePriority, width, height, shadowSurface);
+void AnimatedSprite::createShadowSurface(const Common::SharedPtr<BaseSurface> &shadowSurface, int16 width, int16 height, int surfacePriority) {
+ _surface.reset(new ShadowSurface(_vm, surfacePriority, width, height, shadowSurface));
}
void AnimatedSprite::startAnimation(uint32 fileHash, int16 plFirstFrameIndex, int16 plLastFrameIndex) {
diff --git a/engines/neverhood/sprite.h b/engines/neverhood/sprite.h
index 28f0f83da92..b19a7a7c3b7 100644
--- a/engines/neverhood/sprite.h
+++ b/engines/neverhood/sprite.h
@@ -54,10 +54,9 @@ const int16 kDefPosition = -32768;
class Sprite : public Entity {
public:
Sprite(NeverhoodEngine *vm, int objectPriority);
- ~Sprite() override;
void init() {}
- BaseSurface *getSurface() { return _surface; }
- virtual BaseSurface *getSubtitleSurface() { return nullptr; }
+ Common::SharedPtr<BaseSurface> getSurface() { return _surface; }
+ virtual Common::SharedPtr<BaseSurface> getSubtitleSurface() { return nullptr; }
void updateBounds();
void setDoDeltaX(int type);
void setDoDeltaY(int type);
@@ -87,7 +86,7 @@ protected:
Common::String _spriteUpdateCbName; // For debugging purposes
int16 (Sprite::*_filterXCb)(int16);
int16 (Sprite::*_filterYCb)(int16);
- BaseSurface *_surface;
+ Common::SharedPtr<BaseSurface> _surface;
int16 _x, _y;
bool _doDeltaX, _doDeltaY;
bool _needRefresh;
@@ -151,7 +150,7 @@ public:
int16 getFrameIndex(uint32 frameHash) { return _animResource.getFrameIndex(frameHash); }
void setNewHashListIndex(int value) { _newStickFrameIndex = value; }
void startAnimation(uint32 fileHash, int16 plFirstFrameIndex, int16 plLastFrameIndex);
- BaseSurface *getSubtitleSurface() override { return &_subtitleSurface; }
+ Common::SharedPtr<BaseSurface> getSubtitleSurface() override { return _subtitleSurface; }
protected:
class AnimatedSpriteSubtitles : public BaseSurface {
public:
@@ -162,7 +161,7 @@ protected:
};
static const int kSubtitleWidth = 320;
- AnimatedSpriteSubtitles _subtitleSurface;
+ Common::SharedPtr<AnimatedSpriteSubtitles> _subtitleSurface;
typedef void (AnimatedSprite::*AnimationCb)();
Common::ScopedPtr<SubtitlePlayer> _subtitles;
AnimResource _animResource;
@@ -190,8 +189,8 @@ protected:
void updateFrameIndex();
void updateFrameInfo();
void createSurface1(uint32 fileHash, int surfacePriority);
- void createShadowSurface1(BaseSurface *shadowSurface, uint32 fileHash, int surfacePriority);
- void createShadowSurface(BaseSurface *shadowSurface, int16 width, int16 height, int surfacePriority);
+ void createShadowSurface1(const Common::SharedPtr<BaseSurface> &shadowSurface, uint32 fileHash, int surfacePriority);
+ void createShadowSurface(const Common::SharedPtr<BaseSurface> &shadowSurface, int16 width, int16 height, int surfacePriority);
void stopAnimation();
void startAnimationByHash(uint32 fileHash, uint32 plFirstFrameHash, uint32 plLastFrameHash);
void nextAnimationByHash(uint32 fileHash2, uint32 plFirstFrameHash, uint32 plLastFrameHash);
More information about the Scummvm-git-logs
mailing list