[Solved] CoordinateDisplay.js error

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

[Solved] CoordinateDisplay.js error

Post by 333onlyhalfevil » Wed Dec 04, 2024 3:14 pm

Hello everyone.

I generally run qcad with the debugger enabled (for debugging my own scripts) and I seem to randomly get an error popping up from CoordinateDisplay when using the program normally. It seems to happen when I'm just clicking on stuff and it doesn't happen too often. I took a screenshot of the debugger window that popped up as a result (see attached image). Seems like a weird error. It is saying that CoordinateDisplay.singleShot is not an object (undefined) even though it apparently wasn't undefined on the previous line? Any ideas?
Attachments
CoordinateDisplayError.jpg
CoordinateDisplayError.jpg (322.12 KiB) Viewed 53261 times
Last edited by 333onlyhalfevil on Fri Dec 06, 2024 11:10 pm, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 8769
Joined: Fri Mar 30, 2007 6:07 am

Re: CoordinateDisplay.js error

Post by andrew » Wed Dec 04, 2024 3:23 pm

333onlyhalfevil wrote:
Wed Dec 04, 2024 3:14 pm
I generally run qcad with the debugger enabled (for debugging my own scripts)
Unfortunately, this is happens because events can occur in the wrong moment while debugging since the debugger forces event processing while running a script. For the same reason, the Qt script debugger can also cause random crashes and should only be enabled when really needed. Note that with Qt 6, the debugger has been removed completely.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: CoordinateDisplay.js error

Post by CVH » Wed Dec 04, 2024 4:25 pm

andrew wrote:
Wed Dec 04, 2024 3:23 pm
Note that with Qt 6, the debugger has been removed completely.
That is very bad news.
Does that mean that users that develop scripts must stick to Qt5?

And how can scripts be debugged under Qt6?


@333onlyhalfevil
I simply ignore them, hit run.
For a steady state you need to run QCAD without debugger.
I then swap frequently between with/without debugger with two QCAD icons on my desktop.

When it hangs there is an issue and then I close QCAD and swap to the debugger mode.
For the time being ....

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: CoordinateDisplay.js error

Post by 333onlyhalfevil » Thu Dec 05, 2024 9:02 am

Ok. I'll just ignore it then. Thank you both for the replies.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: CoordinateDisplay.js error

Post by CVH » Thu Dec 05, 2024 2:05 pm

333onlyhalfevil wrote:
Thu Dec 05, 2024 9:02 am
Ok. I'll just ignore it then.
Yep, probably a cursor or click event that is misfired.
Always run your flawless scripts without the debugger mode in a stable environment ... Too.

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: [Solved] CoordinateDisplay.js error

Post by 333onlyhalfevil » Thu May 15, 2025 9:43 am

i got sick of this one popping up randomly and ended up fixing it. You can fix it by editing the following file https://github.com/qcad/qcad/blob/f06ae ... lay.js#L25 as follows:

The problem is that an undefined gets passed through the script sometimes and causes the debugger to pop up. Line 81 in CoordinateDisplay.js checks if CoordinateDisplay.singleShot is null. Add in another check to make sure CoordinateDisplay.singleShot is not undefined like so: && CoordinateDisplay.singleShot != undefined. You also need to change line 107 to an else if and add in the same two checks for null and undefined. It hasn't popped up since making these edits.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: [Solved] CoordinateDisplay.js error

Post by CVH » Thu May 15, 2025 11:45 am

Thanks for your trouble but could you format your solution in code panels.

CoordinateDisplay.js is typically only included as compiled in a standard installation.
Meaning that we have to supersede it with including a custom copy ourselves and the required folder structure + whatever required.

Odd is that isNull(obj) is said to check if the given object is undefined or null, see the library.js script.
The extra test on 'undefined' on line 81 should be obsolete.
It would then fail in line 82 checking the active state of not a QTimer.

I can't let it misfire on purpose with flawless scripts at the moment and can thus not verify if that is the case.
Your own screen capture above displays the error at line 106 (That is from before Commit 5a73fc9 .. Oct 20, 2022)
Mentioned yourself, set to a QTimer on line 103 but failed 3 lines lower.
You can not catch this off by an extra test on 'undefined' in line 81 or 107 (current state).
Because it would fail somewhere between 107 and 111 (current state).

Events are simply not executed at due time or in the correct order in debugger mode.
Things may happen between evaluating and executing 2 lines of JS code.


But if it fixed all of your issues with singleShot ... Then why not.

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: [Solved] CoordinateDisplay.js error

Post by 333onlyhalfevil » Thu May 15, 2025 12:56 pm

CVH wrote:
Thu May 15, 2025 11:45 am
Thanks for your trouble but could you format your solution in code panels.
Sure, here's the updated function:

Code: Select all

CoordinateDisplay.update = function(documentInterface) {
    if (!CoordinateDisplay.widget.enabled) {
        return;
    }

    if (isNull(documentInterface)) {
        // clear texts (no document open):
        CoordinateDisplay.lAbs.setText("");
        CoordinateDisplay.lAbsPol.setText("");
        CoordinateDisplay.lRel.setText("");
        CoordinateDisplay.lRelPol.setText("");
        return;
    }

    if (!isNull(CoordinateDisplay.singleShot) && CoordinateDisplay.singleShot != undefined) {
        if (CoordinateDisplay.singleShot.active) {
            // never mind previous update:
            CoordinateDisplay.singleShot.stop();
        }
        if (!isNull(CoordinateDisplay.singleShot)) {
            // catch exception when ran with script debugger:
            try {
                CoordinateDisplay.singleShot.destroy();
                CoordinateDisplay.singleShot = undefined;
            }
            catch(e) {}
        }
    }

    // force immediate update every X mouse moves
    CoordinateDisplay.counter++;
    if (CoordinateDisplay.counter>=CoordinateDisplay.forcedUpdateInterval) {
        //CoordinateDisplay.singleShot.start(0);
        CoordinateDisplay.timedUpdate();
        CoordinateDisplay.counter = 0;
    }
    else if (!isNull(CoordinateDisplay.singleShot) && CoordinateDisplay.singleShot != undefined) {
        CoordinateDisplay.singleShot = new QTimer();
        CoordinateDisplay.singleShot.singleShot = true;
        CoordinateDisplay.singleShot.timeout.connect(CoordinateDisplay.timedUpdate);
        CoordinateDisplay.singleShot.start(20);
    }
};
CVH wrote:
Thu May 15, 2025 11:45 am
Odd is that isNull(obj) is said to check if the given object is undefined or null, see the library.js script.
The extra test on 'undefined' on line 81 should be obsolete.
Interesting. It looks like the comment says that it checks for undefined but the code itself does not. It appears to only check for if the object is deleted, if its null, and if it has a typeof equal to "function". Maybe a simpler solution would be to add the undefined check within the isNull() function. A quick internet search for isDeleted says an undefined is only used in the case of arrays. Maybe that is the confusion.
CVH wrote:
Thu May 15, 2025 11:45 am
It would then fail in line 82 checking the active state of not a QTimer.

I can't let it misfire on purpose with flawless scripts at the moment and can thus not verify if that is the case.
My memory is a little fuzzy on this since I posted it awhile ago but I seem to remember the error line not being the same line every time the debugger popped up. It always seemed to fail on either line 84 or lines 108-111. It's possible that it is still a problem within flawless scripts because if you continue running after the debugger popup, it will just keep going until it gets back to the beginning where CoordinateDisplay.singleShot gets assigned a value.
CVH wrote:
Thu May 15, 2025 11:45 am
Your own screen capture above displays the error at line 106 (That is from before Commit 5a73fc9 .. Oct 20, 2022)
Mentioned yourself, set to a QTimer on line 103 but failed 3 lines lower.
You can not catch this off by an extra test on 'undefined' in line 81 or 107 (current state).
Because it would fail somewhere between 107 and 111 (current state).
This is a good point. Maybe its not completely fixed in that case and it'll end up popping up again eventually. It certainly helped though.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: [Solved] CoordinateDisplay.js error

Post by CVH » Thu May 15, 2025 1:30 pm

It seems your are mixing things ...

CoordinateDisplay.singleShot.destroy(); is deprecated on Mar 22, 2023 (Commit 55d1538)
In a recent installation it should read:
destr(CoordinateDisplay.singleShot);

Basically does the same if a destroy function exists, otherwise it does nothing.

But still, if you are mixing things what have you mixed elsewhere?

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: [Solved] CoordinateDisplay.js error

Post by 333onlyhalfevil » Thu May 15, 2025 3:58 pm

I don't upgrade qcad to the new version every time a new one comes out. It looks like it was rolled back to the CoordinateDisplay.singleShot.destroy() way shortly after your linked commit (v3.26.2.5) and it wasn't updated back to the destr(CoordinateDisplay.singleShot) way until 3.28.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: [Solved] CoordinateDisplay.js error

Post by CVH » Thu May 15, 2025 4:44 pm

Good thing that I made adding an RWipeoutEntity relative to having the proper resources then (Block Labels). :)
Perhaps I keep it optionally ... Time will tell.

So, what release are you running?
This is also important to know when formulating an answer for a particular solution.


I stopped updating after v3.27.6.0 but have trial installations aside including the most recent.
v3.27.7 introduced an extreme lag for certain properties of Hatches / solid fills.
v3.27.8 introduced 'Show' buttons for these properties I disliked very much.
Finally fixed in v3.32.0 but in these recent releases my mouse wheel may act strange after visiting the App.Prefs. or a Print Preview.

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: [Solved] CoordinateDisplay.js error

Post by 333onlyhalfevil » Sat May 17, 2025 11:08 pm

I'm on 3.27.6.0 too

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”