HTML: Stall during loading of a collection proxy

Our application seems to stall upon loading a collection proxy; however it only happens for a specific collection (stripping out objects and re-running does not seem to make any difference either). Behaviour is consistent regardless of using Chrome, FF or Safari. The Defold engine appears still to be running and there are no related errors reported by the browser debugger (from what I can tell).

Running on OS-X, Windows and Android works just fine.

Is there any log output generated for HTML builds? Right now it is hard to say where it stalls.

1 Like

Actually, it looks like a problem with lua modules (not entirely consistent to reproduce though).

First I had to move the includes / requires to a script executed as part of the bootstrap collection; then I can see that there is an exception thrown (also communicated by the engine).

Seems a module construction like this cause problems (for some local variables)
…
local M = {}
local ANIM = {hash(“player_bullet_1”), hash(“player_bullet_2”), hash(“player_bullet_3”), hash(“player_bullet_4”)}
…

But replacing with:
…
local M = {}
M.ANIM = {hash(“player_bullet_1”), hash(“player_bullet_2”), hash(“player_bullet_3”), hash(“player_bullet_4”)}
…

Would suddenly make it work (seemed like a pattern for most of our modules).

Haven’t really considered how lua modules work, but since it “just worked” for other platforms - maybe its a bug?

Maybe its related to obfuscation (in lack of better terms)

Since this works:

M.profiles = {{value = 15, factory = nil, duration = 8, distance = 128, factory_fragment = “collectable_coin_factory”, expire_anim_id = hash(“bee_coin_flicker”)},
{value = 10, factory = nil, duration = 8, distance = 256, factory_fragment = “collectable_rock_factory”, expire_anim_id = hash(“rock_coin_flicker”)}}

But this would cause an exception:

M.profiles = {{factory = nil, value = 15, duration = 8, distance = 128, factory_fragment = “collectable_coin_factory”, expire_anim_id = hash(“bee_coin_flicker”)},
– {factory = nil, value = 10, duration = 8, distance = 256, factory_fragment = “collectable_rock_factory”, expire_anim_id = hash(“rock_coin_flicker”)}}

Same content, just shuffled.

It’s really hard to tell what’s wrong just by looking at the small snippets of table declarations you have provided. But, assuming M is the table you return from your module file:

local M = {}
-- module declarations go here
return M

Then there’s a big difference in how you’d access and use ANIM in your first example. If you do local ANIM = {} then the ANIM table will be accessible to the code in your module, but not to code that require() the module. Consider ANIM a privately declared table. If you do M.ANIM = {} then it becomes accessible to scripts that require() the module.

If you’re uncertain how modules work and what happens when you require() a module I can recommend that you read up on modules and the require() function in the official Lua documentation and in the Defold documentation.

Well, from the beginning they were declared local, as they were / are only used within the module. Since that apparently prevented the module from being loaded (causing an engine exception), I changed them to become members of the module (which made the code load fine). However, since I assumed it would work in the first place, I started reverting some of the changes. Then I noticed that local vs. non local declaration didn’t seem to cause the exception, but rather the order of declaration (or similar). That triggers me to believe it is engine / lua / build related.

Can you isolate this into a minimal example so that I can try it myself?