Skip to content

tiled crash when trying to select an object in warn/error callback from issues view #4189

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

Open
thmsndk opened this issue Apr 8, 2025 · 4 comments
Labels
bug Broken behavior.

Comments

@thmsndk
Copy link

thmsndk commented Apr 8, 2025

Describe the bug
When registering a callback for tiled.warn or tiled.error and clicking on it in the issue tab tiled crashes when setting selected or trying to change selectedObjects

tiled.warn("test", function () {
	if (obj) {
		// First select the object
                obj.map.selectedObjects = [];
		obj.map.selectedObjects.push(obj);
		// obj.layer.selected = true;
		// obj.selected = true;

		// Then center the view on it
		tiled.mapEditor.currentMapView.centerOn(obj.x + obj.width / 2, obj.y + obj.height / 2);
	}
});

To Reproduce
Steps to reproduce the behavior:

  1. Go to the issues tab
  2. Double Click on 'the warning or error
  3. tiled crashes to desktop with no error

Expected behavior
That the object would be selected in the tiled editor

Specifications:

  • OS: Windows 11
  • Tiled Version: 1.11.2
@thmsndk thmsndk added the bug Broken behavior. label Apr 8, 2025
@bjorn
Copy link
Member

bjorn commented Apr 9, 2025

Hmm, this isn't crashing Tiled on my system (Linux) either on latest master or using the 1.11.2 release. Rather it's doing exactly what it's supposed to do (though I hadn't really expect push to work).

It seems rather unlikely that this issue would depend on the operating system. Maybe it depends on the Qt version? Are you using the 32-bit of 64-bit version of Tiled?

Could you try whether it also crashes when you just do this instead:

obj.map.selectedObjects = [obj];

@thmsndk
Copy link
Author

thmsndk commented Apr 9, 2025

The installer I used was called Tiled-1.11.2_Windows-10+_x86_64.msi

The code I provided I think is doing the same, e.g. making a new array and then pushing to it, I've tried a few variants. The centerOn method works great and it moves to the position.

Is there perhaps something wrong with the object i'm putting into the list? Is it because I need to select the layer first via code? the obj in question should be a MapObject (Polygon or Rectangle), and the toolbar for selecting an object requires me to be on the object layer first.

I'll see if I can make a smaller reproduce in another test project

@thmsndk
Copy link
Author

thmsndk commented Apr 11, 2025

I've created a reproduce repository here https://drive.google.com/drive/folders/14GUFRjK77p1ep700L9dVvCyCOVgDETly?usp=sharing since I can not attach it as a 7zip file.

  • enable project extension when it asks
  • press ctrl + e to export the map with the Map Exporter
  • press ok to the alert
  • tiled now crashes

The following code snippet is the extension in the extensions folder next to the project in case I remove the drive link at some point

function createErrorCallback(obj = undefined) {
	return () => {
		tiled.alert("tiled is crashing now");
		if (obj) {
			// First select the object
			// TODO: Figure out how to do this, my attempts  to do this crashes tiled
			obj.map.selectedObjects = [];
			obj.map.selectedObjects.push(obj);
			// obj.layer.selected = true;
			// obj.selected = true;

			// Then center the view on it
			tiled.mapEditor.currentMapView.centerOn(obj.x + obj.width / 2, obj.y + obj.height / 2);
		}
	};
}

// Register the format
const mapDataFormat = {
	name: "Map Exporter",
	extension: "json",
	write: function (map, fileName) {
		tiled.log("Processing " + map.layerCount + " layers...");
		for (let i = 0; i < map.layerCount; ++i) {
			const layer = map.layerAt(i);
			for (let i = 0; i < layer.objectCount; ++i) {
				const obj = layer.objectAt(i);

				tiled.error(`Object ${obj.name} error, double click to select`, createErrorCallback(obj));
			}
		}

		return ""; // When a non-empty string is returned, it is shown as error message.
	},
};

tiled.registerMapFormat("mapData", mapDataFormat);
tiled.log("MapData format registered successfully!");

@thmsndk
Copy link
Author

thmsndk commented Apr 11, 2025

I have just used obj.map.selectedObjects = [obj] in an ordinary tiled extension, and it works here on the callback. I think perhaps the crash is related to the fact that the error callback comes from a registerMapFormat method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior.
Projects
None yet
Development

No branches or pull requests

2 participants