• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Help with Desync issues

Level 7
Joined
Jul 21, 2016
Messages
49
About 50% of the time I play my map it crashes. It can happen anywhere from within the first couple of minutes or up to an hour in. I am on discord with all players as we are playing and I ask them each time if they were doing something interesting. Each time none of the players have anything interesting to report. I must have watched up to 50 replays of point of views of the players as it desyncs. I cannot spot what is causing the game to crash. Most of the time it crashes only part of the lobby and the rest can remain playing, a.k.a. only team 1 crashes or only a subsection of a team crashes. It feels like it is caused by a trigger which causes desyncs between the players. I have been going through all my code trying to remove any triggers that could potentially cause desyncs, but to no avail. I still have 1 suspect remaining that I feel like might be causing the desyncs. I use the functions BlzGetFrameByName, BlzFrameSetText tens of thousands of times per game by calling this function:
JASS:
function ChangeFoodTextBox takes nothing returns nothing
    local framehandle fh = BlzGetFrameByName("ResourceBarSupplyText" , 0)
    local player myplayer = GetLocalPlayer()
    local integer mynumber = GetConvertedPlayerId(GetTriggerPlayer())
    local string ftext = ""

    set ftext = I2S(( GetPlayerState(myplayer, PLAYER_STATE_RESOURCE_FOOD_CAP) - GetPlayerState(myplayer, PLAYER_STATE_RESOURCE_FOOD_USED) ))

    if ( mynumber != 22 ) then
               call BlzFrameSetText(fh , ftext)
       endif
endfunction
Does anyone have any insight on whether or not this function can desync the game? Alternatively, does anyone have a consistent way to trace a desync back to a function call?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
Does anyone have any insight on whether or not this function can desync the game? Alternatively, does anyone have a consistent way to trace a desync back to a function call?
ftext is going to return a different result for everyone since myplayer is the local player. Isn't this trigger intended to run for one specific Player at a time?

I believe here's how you can fix it:
vJASS:
function ChangeFoodTextBox takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer id = GetConvertedPlayerId(p)
    local string txt = I2S(( GetPlayerState(p, PLAYER_STATE_RESOURCE_FOOD_CAP) - GetPlayerState(p, PLAYER_STATE_RESOURCE_FOOD_USED) ))

    if ( id != 22 and p == GetLocalPlayer() ) then
        call BlzFrameSetText(BlzGetFrameByName("ResourceBarSupplyText" , 0), txt)
    endif
    set p = null
endfunction
Now we're only modifying the frames locally and for one player. Also, I addressed the memory leaks.

I've also heard that you can desync if you try to access a specific frame for the first time locally. So perhaps throw this line of code in some kind of Init trigger that happens at the 0.01 second mark (this applies to my solution):
vJASS:
local framehandle fh = BlzGetFrameByName("ResourceBarSupplyText" , 0)
set fh = null
 
Last edited:
Top