Can't debug my function - Object variable not set on the very first line?

It’s been so long since I’ve tried to do anything in BASIC.
I am trying to write a function that given three values for red, green, blue, will set the calling cell’s background to that color and then return that color as #rrggbb in the cell. Whenever I update the function call with a value or a cell address, I always get a very generic looking dialog that gives no indication WHERE the error is occurring

BASIC runtime error.
Object variable not set.

When I set a breakpoint on the function declaration itself, I can see the arguments in the Calls pane of the IDE, and then when I click Step Into, I immediately get the error dialog. I can’t understand what the problem is :dizzy_face:

Function ApplyBackgroundColor(Raddr As Variant, Gaddr As Variant, Baddr As Variant) as String
dim Rval As Long
dim Gval As Long
dim Bval As Long
if IsNumeric(Raddr) Then
  Rval = Raddr
else
  Rval = Raddr.Value
end if
if IsNumeric(Gaddr) Then
  Gval = Gaddr
else
  Gval = Gaddr.Value
end if
if IsNumeric(Baddr) Then
  Bval = Baddr
else
  Bval = Baddr.Value
end if
Application.Caller.CellBackColor = rgb(Rval,Gval,Bval)
ApplyBackgroundColor = "#" & Right(Hex(Rval),2) & Right(Hex(Gval),2) & Right(Hex(Bval),2)
End Function

Its a function with required arguments, so you have to call the function for example like:

sub main
    applyBackgroundColor( 50, 100, 150 )
end sub

I put the call into a spreadsheet like this

=APPLYBACKGROUNDCOLOR(B4,C4,D4)

Where each of those cells has the HSV to RGB formula transliterated from Wikipedia, e.g.

=ROUND(255*($D$1-$D$1*$B$1*MAX(0,MIN(MOD((B$2+$A4/60),6),4-MOD((B$2+$A4/60),6),1))),0)

And I also tried hardcoded values like this

=APPLYBACKGROUNDCOLOR(126,126,126)

What is your program version and OS? Full info from Help → About is needed. Also, providing a sample ODS with the macro would be helpful.

Oops, sorry.
Version: 24.8.6.2 (X86_64)
Build ID: 480(Build:2)
CPU threads: 8; OS: Linux 6.14; UI render: default; VCL: kf6 (cairo+wayland)
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
HSV_to_RGB.ods (28.0 KB)

The document works fine using Version: 25.2.3.2 (X86_64) / LibreOffice Community
Build ID: bbb074479178df812d175f709636b368952c2ce3
CPU threads: 24; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Vulkan; VCL: win
Locale: en-US (en_US); UI: en-GB
Calc: CL threaded

But fails using Version: 24.8.0.3 (X86_64) / LibreOffice Community
Build ID: 0bdf1299c94fe897b119f97f3c613e9dca6be583
CPU threads: 24; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Vulkan; VCL: win
Locale: en-US (en_US); UI: en-GB
Calc: CL threaded

So yes, a problem in the older version, fixed in 25.2.
Specifically, it was tdf#160578.

Key note: UDF (Custom) functions in Calc and Excel have similar limitations:

such a function cannot do any of the following:
Insert, delete, or format cells on the spreadsheet.

By the way, Calc does not support Application.Caller for UDF functions.

FWIW I commented out the Application.Caller.CellBackColor line and the error persists.

@mikekaganski fixed this bug starting with version 25.2 (see his answer above).