Runtime Error when requiring plugin

Hi I’m getting a Runtime Error when I require the plugin on iOS and Android, it appears to be a problem with the plugin itself, I’ve called no other functions and have previously got push working with AWS SNS on both platforms so am confident the API Keys and Certificates are setup correctly. I’m also using the latest daily build  2014.2359:

/Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:104: bad argument #1 to 'time' (table expected, got number) stack traceback: [C]: in function 'time' /Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:104: in function 'get\_timezone' /Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:166: in function 'RegisterOrUpdatePlayer' /Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:293: in function \</Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:270\> ?: in function \<?:218\>

Does any one know what is the cause, the plugin seems to load fine, its after the registration token is received and registration begins with GameThrive the event occurs? 

Thanks. 

It seems like this might be due to something that broke in a recent daily build. We’re investigating now.

Could you try ruining the following code and let me know what it prints, both on your local machine and on your device?

local now = os.time()

print(os.difftime(now, os.time(os.date("!*t", now))))

I see the number 0 within output on Sim and on device. Which I believe is correct right? Thanks for getting back.

Very weird. So the line it’s failing at inside the plugin is this:

local function get_timezone() --line 102

    local now = os.time() --line 103

    return os.difftime(now, os.time(os.date("!*t", now)))  --line 104 (crashing here)

end --line 105

 

The error says that “os.time” received a number instead of a table, but in the documentation of os.date, you’ll see that this request for date should definitely return a table.

 

I’ve tried everything I can think of to reproduce the problem, both with and without building the app in corona enterprise. Best thing I can think of to try next would be to have you send me your project to try it out or a simple test case that also has the same error. Send it to george@gamethrive.com

Is this problem happening for you or just isolated to the project i’m using? It does sound odd. I can create test case maybe but sending the project is not straight forward as we use a build system.

I can’t get it happen at all. If you could send a simple test case that would be great.

Ok thanks. I’m actually using that exact same get_timezone function elsewhere in the project but its local to the function its in, could it possibly be the act of calling os.date more than once within one frame cause trouble??? (Nope I tested this by calling it many times in a row, all was fine as expected)

I decided to change the position of where I load Gamethrive to before I load the script using my time functions and the error still occurred, I then decided to comment all of my code out after loading gamethrive. Bingo it all started to work as expected and registration completed.

Are there any globals within the Gamethrive plugin that could be affected by my code, I assume everything is localised to the plugin? Maybe there is a variable name conflict overriding your values or function.

I still need to do bit more testing to confirm all is working but this bug seems odd indeed, I’ll keep hunting for the exact position of the conflict. Thanks for the help, good to know its just me getting the problem. 

Mystery solved, another team member made this function which was overriding your call to os.date, wow epic misdirection, thank you so much for your assistance I think it’s going be ok now:

os.date = function (str) local date if str == "!\*t" then local date2 = os.dateOld(str) date = os.time(date2) else local date2 = os.dateOld(str) local time = os.time{year=date2.year, month=date2.month, day=date2.day, hour=date2.hour+os.qtTimeOffset, min=date2.min, sec=date2.sec, isdst=date2.isdst, wday=date2.wday, yday=date2.yday} date = os.dateOld( "\*t", time ) end return date end

Ah, yep that would definitely do it. Glad you got it working & happy to help!

It seems like this might be due to something that broke in a recent daily build. We’re investigating now.

Could you try ruining the following code and let me know what it prints, both on your local machine and on your device?

local now = os.time()

print(os.difftime(now, os.time(os.date("!*t", now))))

I see the number 0 within output on Sim and on device. Which I believe is correct right? Thanks for getting back.

Very weird. So the line it’s failing at inside the plugin is this:

local function get_timezone() --line 102

    local now = os.time() --line 103

    return os.difftime(now, os.time(os.date("!*t", now)))  --line 104 (crashing here)

end --line 105

 

The error says that “os.time” received a number instead of a table, but in the documentation of os.date, you’ll see that this request for date should definitely return a table.

 

I’ve tried everything I can think of to reproduce the problem, both with and without building the app in corona enterprise. Best thing I can think of to try next would be to have you send me your project to try it out or a simple test case that also has the same error. Send it to george@gamethrive.com

Is this problem happening for you or just isolated to the project i’m using? It does sound odd. I can create test case maybe but sending the project is not straight forward as we use a build system.

I can’t get it happen at all. If you could send a simple test case that would be great.

Ok thanks. I’m actually using that exact same get_timezone function elsewhere in the project but its local to the function its in, could it possibly be the act of calling os.date more than once within one frame cause trouble??? (Nope I tested this by calling it many times in a row, all was fine as expected)

I decided to change the position of where I load Gamethrive to before I load the script using my time functions and the error still occurred, I then decided to comment all of my code out after loading gamethrive. Bingo it all started to work as expected and registration completed.

Are there any globals within the Gamethrive plugin that could be affected by my code, I assume everything is localised to the plugin? Maybe there is a variable name conflict overriding your values or function.

I still need to do bit more testing to confirm all is working but this bug seems odd indeed, I’ll keep hunting for the exact position of the conflict. Thanks for the help, good to know its just me getting the problem. 

Mystery solved, another team member made this function which was overriding your call to os.date, wow epic misdirection, thank you so much for your assistance I think it’s going be ok now:

os.date = function (str) local date if str == "!\*t" then local date2 = os.dateOld(str) date = os.time(date2) else local date2 = os.dateOld(str) local time = os.time{year=date2.year, month=date2.month, day=date2.day, hour=date2.hour+os.qtTimeOffset, min=date2.min, sec=date2.sec, isdst=date2.isdst, wday=date2.wday, yday=date2.yday} date = os.dateOld( "\*t", time ) end return date end

Ah, yep that would definitely do it. Glad you got it working & happy to help!