[Crash] Map Desync

Level 15
Joined
Aug 16, 2019
Messages
199
Info: The map is on the current Reforged patch. The triggers are in GUI, and I'm gradually rewriting them in JASS. The entire code doesn't involve complex calculations or manipulations; the map is in the altered melee style. Frames are not used.

  1. During network games, desynchronization occurs, and participants get kicked out of the game. How much leakage is there in GUI triggers, and what should I focus on first with such a problem? What should be avoided in the future?
  2. I've read about leaks in Warcraft. When translating code to JASS, I bring it to natives as much as possible, without calling functions within functions. I'm also cleaning up objects in local variables since they remain in memory even after the function exits (about 4 KB for each object). Is there anything else I need to consider that I might have missed?
  3. Globals variables — it's said that they are evil. But how should additional variables be stored that retain information throughout the game? (for the current Reforged patch).
  4. It's a bit late to switch to LUA, but still, if I backtrack and rewrite in LUA, will it be significantly more efficient and productive? Or should I just leave it as it is?
 
Last edited:
Level 15
Joined
Aug 16, 2019
Messages
199
I'm answering my own question, in case someone encounters the same issue and finds this thread.

1. The answer is simple. Certain functions cause player desynchronization, which is well explained in this post:

2. There is an issue. On the current Reforged version, it's better to use Lua, as it has an automatic, proper garbage collector and a more modern syntax.

3-4. Switching to Lua can solve a lot of problems, but again, you need to be careful. To code well with it, it's better to have some programming knowledge under your belt. It’s probably not the best choice for a first programming language, and even more so for Jass (which is simply outdated, though I admit it’s very interesting, given the numerous quirks you need to account for when developing a project).

The topic is completely exhausted.
 
1. During network games, desynchronization occurs, and participants get kicked out of the game. How much leakage is there in GUI triggers, and what should I focus on first with such a problem? What should be avoided in the future?
Good, you found the debug list. When you are unsure, you can check the blizzard.j (for jass) for GetLocalPlayer() and if it calls any native that is non-local, it can cause a desync. It can be hard to know what's local and what's not though...
2. I've read about leaks in Warcraft. When translating code to JASS, I bring it to natives as much as possible, without calling functions within functions. I'm also cleaning up objects in local variables since they remain in memory even after the function exits (about 4 KB for each object). Is there anything else I need to consider that I might have missed?
Calling functions in functions is mostly fine, buy you need to be careful so everything gets cleaned up (at least in "tight loops", where it often. For example every 0.02 seconds).
3.Globals variables — it's said that they are evil. But how should additional variables be stored that retain information throughout the game? (for the current Reforged patch).
You need globals to retain information throughout the game. It's the proper way of doing stuff.
What you need to be careful about is using globals as local-variables. If you have the global integer "tempInt" and use it like this in a trigger:
  • tempInt = 50
  • kill unit a unit
  • Give <tempInt> gold to player.
Here you might think you give 50 gold to the player, but if you have a trigger <On Unit Death> that sets the tempInt to 1, it will give 1 gold to the player, because other triggers can run "in the middle" of another trigger if its even happen!
4.It's a bit late to switch to LUA, but still, if I backtrack and rewrite in LUA, will it be significantly more efficient and productive? Or should I just leave it as it is?
I personally have thought about going LUA a few times, but when I had so many systems and triggers already, I didn't feel like redoing so much, soo... I just keep to jass.
LUA has some advantages and disadvantages. Some old systems are jass-only and other systems are LUA only...
 
Level 15
Joined
Aug 16, 2019
Messages
199
Did you solve your desync? What was the cause? I am currently experiencing a weird desync since I started using LUA, that seems to have nothing to do with any of the LUA function. The game simply desyncs after researching X amount of upgrades. And I have no idea why.
Regarding Lua, I can't provide any advice, as it's likely that not all desync issues have been identified. Specifically, I encountered this error: "b. GUI Function 'Select unit group <group> for player <player>', alias JASS function SelectGroupForPlayerBJ."
 
Level 15
Joined
Aug 16, 2019
Messages
199
Good, you found the debug list. When you are unsure, you can check the blizzard.j (for jass) for GetLocalPlayer() and if it calls any native that is non-local, it can cause a desync. It can be hard to know what's local and what's not though...

Calling functions in functions is mostly fine, buy you need to be careful so everything gets cleaned up (at least in "tight loops", where it often. For example every 0.02 seconds).

You need globals to retain information throughout the game. It's the proper way of doing stuff.
What you need to be careful about is using globals as local-variables. If you have the global integer "tempInt" and use it like this in a trigger:
  • tempInt = 50
  • kill unit a unit
  • Give <tempInt> gold to player.
Here you might think you give 50 gold to the player, but if you have a trigger <On Unit Death> that sets the tempInt to 1, it will give 1 gold to the player, because other triggers can run "in the middle" of another trigger if its even happen!

I personally have thought about going LUA a few times, but when I had so many systems and triggers already, I didn't feel like redoing so much, soo... I just keep to jass.
LUA has some advantages and disadvantages. Some old systems are jass-only and other systems are LUA only...
Thank you very much for the detailed and concise response.

I don’t see any issues with coding in Jass or Lua; it’s more a matter of feasibility. I’m familiar with coding standards, as I am a full-stack web developer (PHP+Python+JS+TS). I’ve seen the nuance about global variables being replaced with hashtables—allegedly, this is faster. However, in the pursuit of performance, Lua turns out to be the winner.

But if we go back to the fact that map-making is just a hobby, there’s no point in radically changing the project code at this stage. I will only address desync issues and eliminate GUI leaks using Jass.
 
Level 15
Joined
Aug 16, 2019
Messages
199
Switching to Lua may introduce you to another world of desyncs. Unless you're going to code every bit of the map yourself (as in you have the knowledge to debug everything in the stack), I suggest you to stick to Jass. The cake is a lie.

Thank you very much for your answer.

I solved the main problems. So far I see no apparent reason to transfer to Lua.
 
Top