Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that texture width and height is valid before creating texture #8579

Merged
merged 4 commits into from Feb 23, 2024

Conversation

britzl
Copy link
Contributor

@britzl britzl commented Feb 22, 2024

Calling resource.create_texture() with a width and/or height of zero crashed the engine. This change will check that the width and height are valid and throw a Lua error otherwise.

Fixes #8578

PR checklist

  • Code
    • Add engine and/or editor unit tests.
    • New and changed code follows the overall code style of existing code
    • Add comments where needed
  • Documentation
    • Make sure that API documentation is updated in code comments
    • Make sure that manuals are updated (in github.com/defold/doc)
  • Prepare pull request and affected issue for automatic release notes generator
    • Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
    • Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
    • Pull request - Link the pull request to the issue(s) it is closing. Use on of the approved closing keywords.
    • Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
    • Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
    • Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.

Example of a well written PR description:

  1. Start with the user facing changes. This will end up in the release notes.
  2. Add one of the GitHub approved closing keywords
  3. Optionally also add the technical changes made. This is information that might help the reviewer. It will not show up in the release notes. Technical changes are identified by a line starting with one of these:
    1. ### Technical changes
    2. Technical changes:
    3. Technical notes:
There was a anomaly in the carbon chroniton propeller, introduced in version 8.10.2. This fix will make sure to reset the phaser collector on application startup.

Fixes #1234

### Technical changes
* Pay special attention to line 23 of phaser_collector.clj as it contains some interesting optimizations
* The propeller code was not taking into account a negative phase.

@britzl britzl requested a review from Jhonnyg February 22, 2024 19:19
@britzl britzl marked this pull request as draft February 22, 2024 19:36
Jhonnyg
Jhonnyg previously approved these changes Feb 22, 2024
Copy link
Contributor

@Jhonnyg Jhonnyg left a comment

Choose a reason for hiding this comment

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

I think it looks good, I would suggest adding a line in the docstring to say that the width and height must be > 0. What about set_texture? Do we need to do something for that as well?

uint32_t max_mipmaps = (uint32_t) CheckTableInteger(L, 2, "max_mipmaps", 0);

if ((width < 1) || (height < 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant parentheses (nitpick)

engine/gamesys/src/gamesys/scripts/script_resource.cpp Outdated Show resolved Hide resolved
Comment on lines +61 to +65
function test_invalid()
assert_error(function()
resource.create_texture("/test_invalid.texturec", tparams_invalid)
end)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

🤙

@britzl
Copy link
Contributor Author

britzl commented Feb 22, 2024

I think it looks good, I would suggest adding a line in the docstring to say that the width and height must be > 0. What about set_texture? Do we need to do something for that as well?

Good point about set_texture. Let me check!

@britzl
Copy link
Contributor Author

britzl commented Feb 22, 2024

I think it looks good, I would suggest adding a line in the docstring to say that the width and height must be > 0. What about set_texture? Do we need to do something for that as well?

No, that seems to work.

@britzl britzl marked this pull request as ready for review February 23, 2024 06:53
@britzl britzl requested a review from Jhonnyg February 23, 2024 06:53
@britzl britzl merged commit f480c80 into dev Feb 23, 2024
22 checks passed
@britzl britzl deleted the Issue-8578-texture-width-and-height-larger-than-zero branch February 23, 2024 22:41
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.

Creating a texture with width or height smaller than 1 will crash the engine
2 participants