mapeditor/tiled

Do you want to work on this issue?

You can request for a bounty in order to promote it!

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

thmsndk posted onGitHub

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

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];
posted by bjorn 18 days ago

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

posted by thmsndk 18 days ago

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!");
posted by thmsndk 16 days ago

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?

posted by thmsndk 16 days ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests