VL53L0X Info:
Device Name: VL53L0X ES1 or later, Type: VL53L0X, ID: VL53L0CBV0DH/1$1
Rev Major: 1, Minor: 1
VL53L0X: StaticInit
VL53L0X: PerformRefSpadManagement
refSpadCount = 6, isApertureSpads = 0
VL53L0X: PerformRefCalibration
VL53L0X: SetDeviceMode
CurrentMilli 1284
sVL53L0X: PerformSingleRangingMeasurement
Range Status: 0 : Range Valid
RANGE IGNORE THRESHOLD: 0.79
Measured distance: 20
20 65595
sVL53L0X: PerformSingleRangingMeasurement
Range Status: 0 : Range Valid
RANGE IGNORE THRESHOLD: 0.99
Measured distance: 20
20 65597
sVL53L0X: PerformSingleRangingMeasurement
Range Status: 0 : Range Valid
RANGE IGNORE THRESHOLD: 0.80
Measured distance: 21
21 34707016
As you can see, the millis() jump from 1284 after Setup right to 65595 after the first measurement, then to 65597 (plausible 2ms) and then right to 34707016!!
If i don't set laserCheckActive in setup, the millis() work fine.
Why is this happening? How can a libary inflict with millis()?
You created your own main(), so the IDE didn't add one. The one that the IDE would have added calls init(), to set up the hardware, including the timers (that millis() relies on). You don't call init(), so the hardware and timer state is completely unknown.
You need to post a minimal, compileable example which reproduces the problem. The posted code can neither compile nor produce the output you posted, so not easy to help
1.) Another thing i noticed is that it seems that the problem is only as long as the sensor is doing somehing. When the Sensor is disabled, the millis() will continue operating correctly (counting up) but will not reset, e.g. if the last (wrong) value from millis() is e.g. 65597 it will go ..98.99.65600 and so on.
2.) Also the problem only happens if the sensor is there, if disconnected it works fine (i thing the library is checking if the sensor is there
3.) to insure its not a hardware issue i checked the Crystal output (8Mhz) with a scope while a run, and it is spot on. So the clock should be fine.
The code is still not valid, in setup you refer "Wire" which is not included. PLEASE, make AND test a working, minimal sample which reproduces the error.
If you are certain that the code produces the problem, I'd suggest that it is either a bug in the adafruit library (less likely) or a wiring / hardware issue. The library used for the sensor uses interrupts, and if they are messing with the millis counter (which is also an interrupt) somehow that would be the cause. The sensor uses 3v, the Mega uses 5V - are you mixing different voltages, maybe?