Under Review
over 1 year ago

"import Rez" or "using Rez" breaks background resources

I started with the BackgroundTimer sample project, and added a println to its BackgroundTimerServiceDelegate.initialize:

    public function initialize() {
        ServiceDelegate.initialize();
        System.println(Application.loadResource(Rez.Strings.TimerExpired));
    }

Now if I build and run the app, it prints out

Background: Your timer has expired!

(thats the expected output of the println) 

But if I now add "import Rez" or "using Rez" to the top of the file, I get

Error: Illegal Access (Out of Bounds)

Details: Failed invoking <symbol>

Stack:

- initialize() at ./BackgroundTimer/source/BackgroundTimerBackground.mc:23 0x1000027a

- getServiceDelegate() at ./BackgroundTimer/source/BackgroundTimerApp.mc:64 0x10000042

Looking at Rez.mcgen, and the compiler's output at -g, it looks like background code is supposed to access BackgroundRez.*, and that the runtime somehow binds Rez to BackgroundRez while background code is running.

The problem, then, seems to be that "using Rez;" binds Rez at compile time, and so the background code is actually trying to access the foreground resources.

In fact, I can fix it by adding "using BackgroundRez as Rez" instead - but since BackgroundRez seems to be just an implementation detail (ie its not documented anywhere), it seems like a risky thing to rely on. Also, there could be shared code that runs in both the foreground and background - so its not necessarily clear which one to use...

And the *reason* for that "using Rez" is that Rez.Strings.foo without a using generates 20 bytes of code (and $.Rez.Strings.foo generates 26). But with the using its only 18. Its also faster because it looks up the Rez module directly.

Parents
  • Do you receive this in simulator only or also on devices? And do you still encounter the issue or did you find a workaround?

    I had the same issue, but within a barrel. Therefore, I changed the code to remove the using Rez; or using Barrel.Rez; and instead define the strings for each of the apps separately. However, now I get Illegal Access (out Of Bounds) on devices in Background.

Comment
  • Do you receive this in simulator only or also on devices? And do you still encounter the issue or did you find a workaround?

    I had the same issue, but within a barrel. Therefore, I changed the code to remove the using Rez; or using Barrel.Rez; and instead define the strings for each of the apps separately. However, now I get Illegal Access (out Of Bounds) on devices in Background.

Children
No Data