Skip to content

Conversation

@SnuffSocket
Copy link
Contributor

@SnuffSocket SnuffSocket commented Oct 15, 2024

Reasoning for this is the frequent use of "time.time()" which can cause unexpected behaviour, for example in "camera.py":
 Line self.fps = 1 / (self.newft - self.prevft) can trigger "ZeroDivisionError" if the loop runs faster than timer resolution.
 In above case we should handle the possible zero division like so:
  self.fps = 1 / (self.newft - self.prevft) if self.newft > self.prevft else 0
  Or we could use time.perf_counter() instead, but it's not worth ~3x the cycles?
  I do a similar check on my fork along with using a exponential moving average instead.

TLDR:
 Rather than hope that user has a program open that requests a higher timer resolution. Do it ourselves?

@dfgHiatus dfgHiatus added the enhancement New feature or request label Oct 20, 2024
@dfgHiatus dfgHiatus self-assigned this Oct 20, 2024
rc = c_int(winmm.timeBeginPeriod(1))
if rc.value != 0:
# TIMEERR_NOCANDO = 97
print(f"[WARN] Failed to set timer resolution: {rc.value}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use our new locale system for text!

try:
winmm = windll.winmm
except OSError:
#print("[DEBUG] Failed to load winmm.dll")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use our new locale system for text!

@dfgHiatus
Copy link
Contributor

Added some feedback to your PR! Thanks

@SnuffSocket SnuffSocket requested a review from dfgHiatus October 22, 2024 14:42
@dfgHiatus dfgHiatus merged commit 1cba6d3 into Project-Babble:main Oct 22, 2024
1 check passed
@SnuffSocket SnuffSocket deleted the timer-branch branch October 26, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants