Skip to content

A subtle order-of-operation issue #8

@LozenChen

Description

@LozenChen

If you write a lua cs like

function onBegin()
    disablePause()
...
end

and then use a lua cs trigger (but with unskippable = false) to trigger it, then you will actually have 2 frames to skip the cutscene, even if the lua cs seems to prevent pausing
yeah i know we should set unskippable = true in this case, but i just want to write everything here, in case you think this should be improved, or someone else curious about what actually happens

order-or-operation analysis:

Frame 1.

  • LuaCutsceneTrigger.OnEnter called (when Player.Update)
  • LuaCutsceneEntity is created
  • LuaCutsceneEntity is to be added to scene
  • LuaCutsceneEntity.OnEnter invoked
  • Level.Update done

Frame 2.

  • EntityList.UpdateList, LuaCutsceneEntity is actually added into the scene
  • LuaCutsceneEntity is a CutsceneEntity, so Level.StartCutscene is called, and LuaCutsceneEntity.OnBegin is called
  • Level.StartCutscene makes it possible to skip cutscene this frame
  • LuaCutsceneEntity.OnBegin adds a new Coroutine(onBeginWrapper(level)) as a component of itself
	private IEnumerator onBeginWrapper(Level level)
	{
		yield return onBeginRoutine;
		EndCutscene(level);
	}
  • Level.Update begin
  • Check if pause button is pressed
  • If not pause, Scene.Update
  • LuaCutsceneEntity.Update, which leads to its Coroutine component update
  • Coroutine's enumerators consist of one enumerator onBeginWrapper(level), so onBeginWrapper(level).MoveNext is called, which makes enumerator.Current = onBeginRoutine
  • onBeginRoutine is pushed onto Coroutine's enumerators stack

Frame 3.

  • You can still pause and skip cutscene this frame
  • LuaCutsceneEntity.Update, so the Coroutine update
  • onBeginRoutine.MoveNext is called, which finally calls disablePause, that makes level.PauseLock = true, so you can't pause from now on
  • But pause check is before this

Frame 4.

  • You can't pause this frame

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions