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

Set data correctly when recreating dynamic texture in gui #8358

Merged
merged 1 commit into from Jan 4, 2024

Conversation

Jhonnyg
Copy link
Contributor

@Jhonnyg Jhonnyg commented Jan 3, 2024

Bugfix for when recreating a deleted texture within the same frame in GUI:

gui.new_texture(tex_id, img.width, img.height, img.type, img.buffer)
gui.delete_texture(tex_id)
gui.new_texture(tex_id, img.width, img.height, img.type, img.buffer)
gui.set_texture(node, tex_id)

Fixes #8356

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.

@@ -532,6 +532,31 @@ namespace dmGui
return true;
}

static Result MakeDynamicTextureData(DynamicTexture* dynamic_texture, uint32_t width, uint32_t height, dmImage::Type type, bool flip, const void* buffer, uint32_t buffer_size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the dynamic texture functions did the same thing, so I just merged the code paths.

Comment on lines +568 to +576
if (DynamicTexture* t = scene->m_DynamicTextures.Get(texture_hash))
{
if (t->m_Deleted)
{
t->m_Deleted = 0;
return RESULT_OK;
} else {
return MakeDynamicTextureData(t, width, height, type, flip, buffer, buffer_size);
}
else
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual bug:
When a texture exists we un-mark it for deletion here so we can reuse it within the frame, but the buffer with the data has already been deleted. The new data is never put into the buffer, and the old buffer is already deleted by this point so the existing texture will essentially be blank.

@Jhonnyg Jhonnyg added bug Something is not working as expected engine Issues related to the Defold engine gui Issues related to gui components labels Jan 3, 2024
@Jhonnyg Jhonnyg requested a review from JCash January 3, 2024 16:19
@Jhonnyg Jhonnyg merged commit 6a757cf into dev Jan 4, 2024
22 checks passed
@Jhonnyg Jhonnyg deleted the issue-8356-dynamic-texture-recreate branch January 4, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working as expected engine Issues related to the Defold engine gui Issues related to gui components
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Dynamic GUI texture is not set if is created, deleted and created again in the same frame
2 participants