It is currently September 8th, 2024, 2:54 am

Rainmeter.exe crash with unrecognized format code for Lua os.date()

Report bugs with the Rainmeter application and suggest features.
User avatar
nek
Posts: 110
Joined: November 3rd, 2019, 12:00 am

Rainmeter.exe crash with unrecognized format code for Lua os.date()

Post by nek »

Rainmeter.exe crash with unrecognized format code for Lua os.date()

Example: os.date('%P')
%P does not exist as an os.date() format code.

I am trying to use some Date and Time format code for the Lua from
C++ time.h format code | https://learn.microsoft.com/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l
Since I could not find the full list of a format code for Lua 5.1.5 os.date().
Time measure Format Codes these format code works except # E O modifiers.

Minimum code to reproduce the issue.
Skin.ini

Code: Select all

[Variables]
$=1.00

[Rainmeter]
Update=1000

[I]
Measure=Script
ScriptFile=#@#Scripts\init.lua
Disabled=1

[Box]
Meter=Image
W=(80*#$#)
H=(80*#$#)
SolidColor=EDEADE
LeftMouseUpAction=[!CommandMeasure I "test1()"]
@Resources\Scripts\init.lua

Code: Select all

function test1()

  --
  -- These works.
  --
  -- print(os.date('%p'))  -- AM/PM
  -- print(os.date('%e'))  -- Day of month

  --
  -- These does not work. It cause rainmeter.exe to crash.
  --
  print(os.date('%P'))      -- UPPERCASE of p
  -- print(os.date('%#m'))  -- `%m` Month [01-12]. trying to remove leading zero.
  -- print(os.date('%Ec'))
  -- print(os.date('%1'))

end

--
-- function test2() does not work on the Rainmeter.
-- Works on the online site https://onecompiler.com/lua/42m2jajfw
--
function test2()

  local a = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'
  local t, j, s, b, r = {}, 1
  for i=1, #a do
    s = '%'..a:sub(i,i)
    b, r = pcall(os.date, s)
    if b then
      t[j] = s..'  '..r
      j = j + 1
    end
  end

  print(table.concat(t, '\n'))

end
Rainmeter 4.5.21.3750 (64-bit)
Language: English (1033)
Build time: 2024-03-01 21:15:52
Windows 10 Pro 22H2 (build 19045.4651) 64-bit - Japanese (1041)
Path: C:\Apps\Rainmeter\
SkinPath: C:\Apps\Rainmeter\Skins\
SettingsPath: C:\Apps\Rainmeter\
IniFile: C:\Apps\Rainmeter\Rainmeter.ini

Removed all Rainmeter\Plugins\*.dll for testing.

Time measure Format Codes | https://docs.rainmeter.net/manual/measures/time/#FormatCodes
Working with date / time in Lua by jsmorley | https://forum.rainmeter.net/viewtopic.php?t=27625
Lua - os.date() | https://www.lua.org/manual/5.1/manual.html#pdf-os.date
Lua - Date and Time format code | https://www.lua.org/pil/22.1.html
C++ time.h format code | https://learn.microsoft.com/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l
Last edited by nek on July 23rd, 2024, 11:25 pm, edited 4 times in total.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Rainmeter.exe crash with unrecognized format code for Lua os.date()

Post by Yincognito »

nek wrote: July 23rd, 2024, 8:12 pm@Resources\Scripts\init.lua

Code: Select all

  -- print(os.date('%#m'))  -- `%m` Month [01-12]. trying to remove leading zero.
This doesn't seem to mention the possibility of crashing when the datetime format string doesn't exist, but it does mention the leading zero thingy:
https://forum.rainmeter.net/viewtopic.php?t=27625
It might be of some help, until the devs have their say on the crash issue.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Brian
Developer
Posts: 2725
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Rainmeter.exe crash with unrecognized format code for Lua os.date()

Post by Brian »

Thanks for reporting. This has been fixed, sort of.

The crash actually happens in a CRT function provided by Windows. While we can't fix the actual issue, we can prevent the CRT from crashing Rainmeter by handling the invalid parameter in this case.

We had to do this for the time measure in the past.

I also added a generic error message to the log in these cases (if Debug=1). It won't help much to identify "where" the problem is, but at least it won't crash Rainmeter. An actual debug build of Rainmeter (or using Visual Studio in debug mode) will log which function,file, line number and expression....but I'm pretty sure not too many people do this.

-Brian

PS - The Lua docs never say anything about removing leading zero's for os.date like strftime does with # (even though os.date does use a version of strftime under the hood).