KEMBAR78
GRAPHICS: Fix cursor surface when bytes per pixel greater than one by OMGPizzaGuy · Pull Request #4898 · scummvm/scummvm · GitHub
Skip to content

Conversation

@OMGPizzaGuy
Copy link
Member

No description provided.

@OMGPizzaGuy OMGPizzaGuy requested review from mikrosk and sev- April 10, 2023 17:17
_size = surf.w * surf.h * surf.format.bytesPerPixel;

// make sure that the width == pitch
_surf.init(surf.w, surf.h, surf.w, new byte[_size], surf.format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this looks like Surface::copyFrom.
In this case, a _surf.free() must be called inside the destructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this init sets the pixels with new[], the destructor currently uses delete[] (byte *)_surf.getPixels()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. The new[] statement is crucial. Had we used create, linearity of the buffer wouldn't be guaranteed. So we must to delete[] it and not free it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. The new[] statement is crucial. Had we used create, linearity of the buffer wouldn't be guaranteed.

I don't understand what you mean by this.
What new[] brings over malloc used in create which prevents us to use create instead of these lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't make assumptions of what create does. I just happen to know because I was to one who changed its (malloc) behaviour for my platform: https://github.com/scummvm/scummvm/blob/master/graphics/blit-atari.cpp#L101

@mikrosk
Copy link
Contributor

mikrosk commented Apr 10, 2023

Good catch. I did test it with USE_RGB_COLOR enabled but I didn't realize that the default cursor is still 8-bit.

@sev-
Copy link
Member

sev- commented Apr 10, 2023

Thanks!

@sev- sev- merged commit d456052 into scummvm:master Apr 10, 2023
@OMGPizzaGuy OMGPizzaGuy deleted the cursor-bpp-fix branch August 28, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants