Skip to content
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

Fix: changedMonitors.forEach (montage.js) #4039

Merged
merged 2 commits into from
May 24, 2024

Conversation

IgorA100
Copy link
Contributor

Iterating through the array was incorrect

Possible fixes #4037

Iterating through the array was incorrect
@connortechnology
Copy link
Member

It does not fix it.

In my testing here, I went over every monitor instead of just the changed ones. That also didn't help, because the actual width of the monitor was different, so setting the fixed ratio didn't help.

@@ -798,7 +798,7 @@ function initPage() {

setInterval(() => { //Updating GridStack resizeToContent, Scale & Ratio
if (changedMonitors.length > 0) {
changedMonitors.forEach(function(item, index, object) {
changedMonitors.slice().reverse().forEach(function(item, index, object) {
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear to the casual observer why the slice and reverse are neccessary. perhaps a comment would help.
Alternatively a simple for loop instead of a forEach is actually faster and you can just clear the array at the end. Would be easier to read as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the time of execution of this code, other data may be filled into the "changedMonitors" array. Therefore, it cannot be cleaned after processing all elements. Step by step cleaning is required. This is why "for" is not used.
slice().reverse() - to iterate over a copy of the array from the end, otherwise it will not be possible to correctly remove the processed monitor from the array

Copy link
Member

Choose a reason for hiding this comment

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

Aha! Excellent content for a comment.

So the slice makes a copy... which we could use for on. Maybe we should just use a while with popping off elements until the array is empty... so that if another item gets added we will process 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.

I'm not ready to say anything yet.

@IgorA100
Copy link
Contributor Author

IgorA100 commented May 24, 2024

the actual width of the monitor was different

I can't figure out the reason and I can't reproduce the problem because... All my monitors are the same width. The width of the block is completely controlled by GridStack.
There may be some asynchrony in the code, I'm working on it now.

Is one or more monitors the wrong width? Is there any fundamental difference between monitors with the correct width and those with the wrong one (Monitor type, something else...)?

@connortechnology
Copy link
Member

Id say leave it for now. It's not a big deal.

@IgorA100
Copy link
Contributor Author

I made changes
Try again.

Id say leave it for now. It's not a big deal.

:)

@connortechnology
Copy link
Member

That's got it. Well done.

@connortechnology connortechnology merged commit d00cc6f into ZoneMinder:master May 24, 2024
11 of 18 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.

The placement of monitors on the Montage page is broken again
2 participants