Skip to content

Conversation

@The4codeblocks
Copy link
Contributor

@The4codeblocks The4codeblocks commented Jun 4, 2025

adds:
read/write to canvases
sense canvas width/height (does not include connections)

also should fix #10905

also patched a leak where the texture doesn't get freed when cancelling / pressing ok with no modification / backing out

If your pull request is not translation or serverlist-related, read the list of requirements below and check each box:

  • I have read the contribution guidelines.
  • I have ensured that my code compiles, if applicable.
  • I have ensured that any new features in this PR function correctly in-game, if applicable.

config(byte[].class, (CanvasBuild build, byte[] bytes) -> {
if(build.data.length == bytes.length){
build.data = bytes;
for(int i = 0; i < bytes.length; ++i){
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use System.arraycopy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be done in 14f5af5

public void setPixel(int pos, int index){
if(pos < canvasSize * canvasSize && pos >= 0 && index >= 0 && index < palette.length){
setByte(data, pos * bitsPerPixel, index);
updateTexture();
Copy link
Contributor

Choose a reason for hiding this comment

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

Redrawing the entire texture each time every update would result in unnecessary performance loss especially if the canvas is off screen, could use a flag to mark it was updated and have the texture updated when it's actually drawn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

had the same idea though I didn't implement it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be done in 012a8f0

Dialog dialog = new Dialog();

Pixmap pix = makePixmap(data);
Pixmap pix = makePixmap(data, new Pixmap(canvasSize, canvasSize));
Copy link
Contributor

Choose a reason for hiding this comment

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

The Pixmap is never freed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be done in 96f6a3c


Pixmap pix = makePixmap(data);
Pixmap pix = makePixmap(data, new Pixmap(canvasSize, canvasSize));
Texture texture = new Texture(pix);
Copy link
Contributor

Choose a reason for hiding this comment

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

Texture isn't disposed when cancelling the edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I touched the texture so that's not part of my PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be done in 96f6a3c


dialog.resized(dialog::hide);
dialog.resized(() -> {
texture.dispose();
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of adding texture/pixmap disposing in 4 places, you should add a hide listener and do it there (dialog.hidden(() => {}))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks
also are you sure that the suggested arrow notation is right?

});

dialog.closeOnBack();
dialog.closeOnBack(dialog::hide);
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you change this? Closing hides the dialog, you're just making it hide twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right yeah I just did a substitution, thanks
fixed in 4a02b42

}

if(texture == null){
if(texture == null || updated){
Copy link
Owner

Choose a reason for hiding this comment

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

I don't see you setting updated to false anywhere, meaning it will update every frame once it's set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right
fixed in 4a02b42

Copy link
Owner

Choose a reason for hiding this comment

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

You set update, not updated, which is very different (and will completely break the block)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You set update, not updated

should be fixed in c4fab2d

@Anuken Anuken merged commit 0185b08 into Anuken:master Jun 17, 2025
2 checks passed
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.

misplaced canvas write in multiplayer

3 participants