Log In  
Log In  

This is a really weird bug, but stat calls for pattern index, note index, and "number of ticks played" do not always sync up and sometimes one changes before the other. It was intermittent and hard to track down. In order to compensate for this, I had to write something to insulate myself from it:

function poll_songpos()
  local pat = stat(24)
  local n = stat(21)
  local ticks = stat(26)

  -- compensate for bug (!) where pattern sometimes changes before note
  if pat ~= songpos.pat and n ~= songpos.n then
    songpos.pat = pat
    songpos.n = n

    if songpos.prevticks > 0 and ticks >= songpos.prevticks then
      songpos.ticks = 0
      songpos.waitingforticksync = true
  elseif pat == songpos.pat and n ~= songpos.n then
    songpos.n = n

  -- compensate for bug (!) where pattern sometimes changes before ticks
  if songpos.waitingforticksync then
    if ticks < songpos.prevticks then
      songpos.waitingforticksync = false
    songpos.ticks = ticks
    songpos.prevticks = ticks

(I then changed all other code to use songpos as the source of truth, rather than the stat calls)

However, this caused a big headache and was hard to track down and it would be great if this wrapper were not necessary. Also I'm not 100% sure this wrapper code is completely bulletproof; I simply wrote it out of necessity to get the issue out of the way from the specific cart I was working on.

Sorry I don't have a cart demonstrating the issue, but I will try to make one. I just wanted to get this reported sooner rather than later, in hopes that it might get addressed for the upcoming update :D

EDIT: as a reminder I also have another bug thread about stat(24) returning 0 instead of -1 which hasn't been fixed yet

Thanks again, @zep, for adding these sfx state-related stat calls a while back; it is super fun to get stuff to react to music/sfx, in a way that is not easily possible on most other platforms!

P#59474 2018-11-29 22:35 ( Edited 2018-11-29 22:44)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-05-25 20:54 | 0.010s | 2097k | Q:11