StarCursor nan(ind) - WoWInterface
Thread Tools Display Modes
11-19-20, 06:30 PM   #1
A Defias Bandit
Join Date: Nov 2020
Posts: 3
StarCursor nan(ind)

hi i used the addon StarCursor for some time now and wanted to debug it since it has some issues after the prepatch.

the bug happens sometimes after a loadingscreen and corrupts some calculationand turns a Number into nan(ind) (NotANumber) and freezes the cursor animation. no lua error

the line " print(tostring((-1)^.5)); " also triggers the bug but i dont understand how this NaN affects the other calculations

This would be a fix but i stil would not understand what happens:
if (speed<0 and speed>0) then speed=0; end

The code:

local x,y,speed = 0,0,0; -- cursor (SnowfallCursor by Dyan)
local CursorFrame = CreateFrame("Frame", "CursorFrame", UIParent);
CursorFrame.texture = CursorFrame:CreateTexture();
CursorFrame:SetScript( "OnUpdate", function(frame,elapsed)
local dX = x;
local dY = y;
x, y = GetCursorPosition();
dX = x - dX;
dY = y - dY;
local weight = 2048 ^ -elapsed;
speed = math.min(weight * speed + (1 - weight) * math.sqrt(dX * dX + dY * dY) / elapsed, 1024);
local size = speed / 6 - 50;
if ( size > 0) then
local scale = UIParent:GetEffectiveScale();
CursorFrame.texture:SetPoint("CENTER", UIParent, "BOTTOMLEFT", (x + 0.5 * dX) / scale, (y + 0.5 * dY) / scale);
  Reply With Quote
11-19-20, 07:04 PM   #2
A Molten Giant
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 531
That's not the code for the current version of StarCursor. It was updated on Curseforge back on October 19th. Try updating it first.

If it doesn't work after updating, the only suggestion I have is adding the following line under GetCursorPosition:

x, y = GetCursorPosition();
if not x or not y then return end
  Reply With Quote
11-20-20, 02:12 AM   #3
A Defias Bandit
Join Date: Nov 2020
Posts: 3
yeah i have integrated the code in my own addon but the bug still exists in the current starfallcursor addon.
the cursor position is not the problem as far as i know.
i looked into it and the position allways seems to be a number.

its just that the behaviour is so strange that i dont see the pattern yet.

for example the result from this line is still nan(ind):
if (speed<0 and speed>0) then speed=0; print("reset:",speed); end
but this works
if (speed<0 and speed>0) then speed=1; print("reset:",speed); end

Last edited by biokiwi : 11-20-20 at 02:23 AM. Reason: add example
  Reply With Quote
11-20-20, 05:02 PM   #4
A Molten Giant
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 531
Oh, I didn't catch this at first. The statement "if speed<0 and speed>0 then" does not work. It will never be true.

I also didn't catch this other thing because my last math class was almost two decades ago. (-1)^.5 results in an imaginary number and is not handled by Lua. Why is that there?
  Reply With Quote
11-21-20, 03:44 AM   #5
A Defias Bandit
Join Date: Nov 2020
Posts: 3
at some point in the loading screen the calculations in starcursor turn a number into a nan(ind) NotaNumber.
at that point the condition speed<0 and speed>0 is true for the variable.

(-1)^.5 is a reliable way to produce a NaN. just found it in a forum post and wanted to see the output. But after i added it the addon would bug out right from the start.

i have this as a fix and it works:
if (speed<0 and speed>0) then speed=1; end

but i still would like to know what happens to trigger the bug.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » StarCursor nan(ind)

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off