Recent

Author Topic: Range Check error - works fine after reboot  (Read 1886 times)

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Range Check error - works fine after reboot
« on: December 19, 2023, 10:47:12 pm »
I have an application I made which runs 24/7 after a few weeks i get the error message 'Rage Check Error'. I close the app and start it again but the error comes up before the form is even drawn on the screen. A reboot of the PC and with works perfectly fine again. What is the best way of diagnosing/debugging this issue?

The PC is running Fedora 38 Plasma - QT5
Complied on Lazarus 2.2.6/ FPC 3.2.2
Fedora 38 X64
QT5

Bart

  • Hero Member
  • *****
  • Posts: 5297
    • Bart en Mariska's Webstek
Re: Range Check error - works fine after reboot
« Reply #1 on: December 20, 2023, 12:00:36 am »
Build with -Cr (range checks enabled) and -gl, sou you get a linenumber information in the stacktrace.

Bart

paweld

  • Hero Member
  • *****
  • Posts: 1034
Re: Range Check error - works fine after reboot
« Reply #2 on: December 20, 2023, 09:40:39 am »
According to what you write, it seems to me that somewhere in the code you use GetTickCount - that is, the problem starts after 24 days and 20.5 49 days and 17 hours (corrected after Thaddy's post). Restarting the computer helps because the counter then starts from 0.
Replace GetTickCount with GetTickCount64 and if you are writing the result to a variable then change its type to Int64 QWord - this should solve the problem.
« Last Edit: December 20, 2023, 03:09:10 pm by paweld »
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 14614
  • Sensorship about opinions does not belong here.
Re: Range Check error - works fine after reboot
« Reply #3 on: December 20, 2023, 01:59:18 pm »
That is indeed the correct answer, Pawel, except it wraps every 49,7 days since its value is unsigned. And this has been a very old problem and every programmer could have known this. The issue is not even related to Freepascal but initially related to the Windows API.
It is also documented in the FPC manuals.

GetTickCount returns a cardinal
GetTickCount64 returns a Qword

Never use a signed integer type for either version.
« Last Edit: December 20, 2023, 02:09:39 pm by Thaddy »
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

paweld

  • Hero Member
  • *****
  • Posts: 1034
Re: Range Check error - works fine after reboot
« Reply #4 on: December 20, 2023, 03:07:42 pm »
Quote from: Thaddy
except it wraps every 49,7 days since its value is unsigned.
My bad. Corrected
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 14614
  • Sensorship about opinions does not belong here.
Re: Range Check error - works fine after reboot
« Reply #5 on: December 20, 2023, 03:56:53 pm »
Quote from: Thaddy
except it wraps every 49,7 days since its value is unsigned.
My bad. Corrected
Once it was also my bad, back in my PerfectView days in 1996: So the problem is a permanently recurring one... :'(
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 52
Re: Range Check error - works fine after reboot
« Reply #6 on: December 20, 2023, 08:25:48 pm »
Awesome thanks now that makes sense, yes I am indeed using tickcount64 and I was storing the value as an integer. I have corrected that to a QWord. I was trying to measure the time in ms for network communication between two devices. Is there a better way?

Anyway thank you so much, I knew someone would know my stuff up I am still learning :-)
« Last Edit: December 20, 2023, 08:36:16 pm by TheMouseAUS »

 

TinyPortal © 2005-2018