findAll: endless loop when only using hasNext() - matches have to be consumed with next()

Bug #1789952 reported by JoePue on 2018-08-30

This bug report was converted into a question: question #680207: findAll: endless loop when only using hasNext() - matches have to be consumed with next() .

6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sikuli
High
RaiMan

Bug Description

Hi RaiMan

I have a simple Java method witch will reproduce a extrem critical problem. I can run the following method between 1-3 mins, but always after a unspecific timespan my complete java app is frozen/hanging (no exception, no further log, no stacktrace). The last log lines before the error occurs are:

[debug] RobotDesktop: captureScreen: [1213,115, 150x400]
[840595 debug] Finder2: makeMat: INT_RGB (150x400)
[840595 debug] Finder2: doFind: start
[840600 debug] Finder2: doFind: in original: %99,9901 (?90) 5 msec
[840602 debug] Finder2: doFind: end 7 msec
[840602 debug] Region: findAll: BuildQueueEntry.png has appeared

It seems that the appearing of my image on the screen causes this critical bug. After this event the java app hanging for ever

// The intention of this method is to count the occurence of my image
private static int getBuildQueueSize(DSOServices dsoService) {
  dsoService.switchToBrowser();
  int counter = 0;
  Region searchRegion = Region.create(1213, 115, 150, 400);
  Iterator<Match> it = null;
  while (true) {
    try {
        it = searchRegion.findAll(pattern("BuildQueueEntry.png").similar(0.90f));
        while (it.hasNext()) {
            counter++;
        }
    } catch (FindFailed findFailed) {
        findFailed.printStackTrace();
    }
  }
}

OS: Win10
Java: 1.8.0_181
Sikuli: 1.1.4-SNAPSHOT
IDE: Intellij Idea
Window Commandline Execution

I hope you can help me with a Fix or Workaround!
Joe

JoePue (joepue) on 2018-08-30
description: updated
description: updated
JoePue (joepue) on 2018-08-30
description: updated
JoePue (joepue) on 2018-08-31
description: updated
JoePue (joepue) on 2018-08-31
description: updated
JoePue (joepue) on 2018-08-31
description: updated
RaiMan (raimund-hocke) wrote :

Might be, that you run into a problem with the revised implementation of findAll (I am working on that).

as a workaround you might limit the counter in the hasNext() loop to a max value that makes sense.

Changed in sikuli:
status: New → In Progress
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.4
summary: - Sikuli Java App completely frozen
+ Sikuli Java App completely frozen with findAll

not a bug

Changed in sikuli:
status: In Progress → Invalid
RaiMan (raimund-hocke) wrote :

sorry for the delay.

The reason behind:
Per definition (see docs of findAll()), the returned Iterator does only step to the next iteration, if the current is consumed (done by using it.next()).

This means you implementation with only using hasNext() is an endless loop by default.

Conclusion: It is not possible to count the matches of findAll() without consuming the matches.
So if you need the matches later, you have to store them whicle counting.

There is convenience feature findAllList(), that returns a List<Match>, which is empty on no success.
see docs:
https://sikulix-2014.readthedocs.io/en/latest/region.html#Region.findAll

summary: - Sikuli Java App completely frozen with findAll
+ findAll: endless loop when only using hasNext() - matches have to be
+ consumed with next()
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers