Skip to content

BugFix: repair special exits in speedwalks with corrupt names#4722

Merged
SlySven merged 1 commit intoMudlet:developmentfrom
SlySven:BugFix_repairSpecialExitsInSpeedwalksWithCorrupNames
Jan 30, 2021
Merged

BugFix: repair special exits in speedwalks with corrupt names#4722
SlySven merged 1 commit intoMudlet:developmentfrom
SlySven:BugFix_repairSpecialExitsInSpeedwalksWithCorrupNames

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Jan 30, 2021

This is an error that slipped in as a result of #4526 and resulted in the exit room id being stored as the special exit name in the BGL graph that is built for the A* search algorithm to work on. Consquently if that route was used in a path the special exit command produced for that step was garbage which also tripped off warnings about invalid characters being sent to the MUD as an exit direction.

Thanks to @ryanstadther for bringing this to my attention!

Signed-off-by: Stephen Lyons slysven@virginmedia.com

This is an error that slipped in as a result of Mudlet#4526 and resulted in the
exit room id being stored as the special exit name in the BGL graph that is
built for the A* search algorithm to work on. Consquently if that route was
used in a path the special exit command produced for that step was garbage
which also tripped off warnings about invalid characters being sent to the
MUD as an exit direction.

Thanks to @ryanstadther for bringing this to my attention!

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven SlySven added this to the 4.11.0 milestone Jan 30, 2021
@SlySven SlySven requested a review from a team as a code owner January 30, 2021 22:49
@SlySven SlySven requested a review from a team January 30, 2021 22:49
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Jan 30, 2021

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@SlySven SlySven merged commit f18e000 into Mudlet:development Jan 30, 2021
@SlySven SlySven deleted the BugFix_repairSpecialExitsInSpeedwalksWithCorrupNames branch January 30, 2021 23:15
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Jan 31, 2021

This kind of bug would have been prevented if we could do for (auto [key, value]: with QMap - but we can't, see https://www.kdab.com/qt-range-based-for-loops-and-structured-bindings. It brings a case against using Qt containers and for using std:: ones which are, now, more modern.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Jan 31, 2021

... and for using std:: ones which are, now, more modern.

Which have their own peculiarities to trap the unwary.

What caused this bug to slip through was multiple compilers not spotting that I was assigning an int to a QString - my best guess is that there are so many QString constructors that possibly the one that took a single int and converted it to a QChar was being used. I expect a std::string constructor would probably do the same. So whilst the error was an oversight of mine I do not believe that using a Qt class was the cause of this. Fortunately someone spotted it and reported it and we fixed it before it got into a release version.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Jan 31, 2021

It was bad semantics, I believe, which the std:: containers help solve. The compiler should be the last line of defense, not the first one.

If you look at this diff, you have no idea what the key and value change is:

image

Because the names mean absolutely nothing. You have to dig further to find their meaning.

Meanwhile, if we gave them meaningful names, it will be much easier to work with it so consider pseudocode:

        for (auto [exit, roomid] : getSpecialExits())) {
            if (pSourceR->hasSpecialExitLock(exit)) {
                continue; // Is a locked exit so forget it...
            }

Instead of:

        QMapIterator<QString, int> itSpecialExit(pSourceR->getSpecialExits());
        while (itSpecialExit.hasNext()) {
            itSpecialExit.next();
            if (pSourceR->hasSpecialExitLock(itSpecialExit.key())) {
                continue; // Is a locked exit so forget it...
            }

I believe the former is far more understandable and less bugs will happen.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Jan 31, 2021

The bug was no less likely to happen IMNSHO if, when the changes (from getOtherMap() to getSpecialExits()) was done one did not also remember to swap around the two variable names:

-        for (auto [roomid, exit] : getOtherMap())) {
+        for (auto [exit, roomid] : getSpecialExits())) {

and I cannot see that I would have immediate been more likely to have spotted the issue there than in the existing code. Probably less so because of the lesser exposure to using auto and range-based loops.

To be perfectly frank it would have been equally valid to have had a local reference/copy of the value to the element concerned like I already had for the room id (as target):

-target = itSpecialExit.key();
-const QString exitName = itSpecialExit.value();
+target = itSpecialExit.value();
+const QString exitName = itSpecialExit.key();

which was indeed done in some other places and made the change over much simpler in those cases - however with only two uses of that item it was marginal as to whether it would have been worth it.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Feb 1, 2021

Now we know that it was, since a bug was caused without it.

Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
…#4722)

This is an error that slipped in as a result of Mudlet#4526 and resulted in the
exit room id being stored as the special exit name in the BGL graph that is
built for the A* search algorithm to work on. Consquently if that route was
used in a path the special exit command produced for that step was garbage
which also tripped off warnings about invalid characters being sent to the
MUD as an exit direction.

Thanks to @ryanstadther for bringing this to my attention!

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants