getTimer() equivalency and compiler errors

Not sure I understand equivalency of flash.utils.getTimer() in OpenFL. Both in terms of measuring time, as well as measuring elapsed runtime since start of the application.

Presumably openfl.Lib.getTimer() should be used in place of flash.Lib.getTimer()?

In Haxe, I thought getTimer() was only available when targeting Flash platform; however, it appears functional cross-platform. Is that so?

There are also occurrences in projects where I receive compiler errors when using getTimer(); although, I’m not exactly sure how to reproduce or isolate the issue. It may be tied to initialization or some order of operations.

While targets using getTimer() always function perfectly on Flash, mac throws compiler error:

Error : Null Function Pointer

Or targeting neko, I receive compiler error:

Called from blitting/core/Blitting.hx line 32
Called from blitting/core/Blitting.hx line 24
Called from a C function
Called from blitting/core/Blitting.hx line 110
Called from blitting/core/Blitting.hx line 114
Called from openfl/Lib.hx line 85
Called from lime/system/System.hx line 239
Uncaught exception - Invalid call

Any idea what this might relate to?

In Haxe without OpenFL, getTimer() is only available when targeting Flash. OpenFL provides the cross-platform implementation, so you can use it as long as you’re using OpenFL.

If you go to System.hx, here’s what you’ll find:

public static function getTimer ():Int {
    #if flash
    return flash.Lib.getTimer ();
    #elseif js
    return cast ().getTime ();
    #elseif !disable_cffi
    return lime_system_get_timer (); //<-- Line 239
    #elseif cpp
    return (untyped __global__.__time_stamp () * 1000);
    #elseif sys
    return (Sys.time () * 1000);
    return 0;

Why would that be a null function pointer? Let’s look at its definition:

private static var lime_system_get_timer = System.load ("lime", "lime_system_get_timer", 0);

I can think of two possibilities here:

  1. That code hasn’t been run yet.
  2. System.load() returned null.

The first could happen if you’re running code in static initializers. The second would mean it can’t find the right lime.ndll file.

1 Like