obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

Websocket API crash and settings corruption when recreating active scene

Open timmaclean opened this issue 1 year ago • 2 comments

Operating System Info

Windows 11

Other OS

No response

OBS Studio Version

30.1.2

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/FHZeBkwviLAZ7XnQ

OBS Studio Crash Log URL

https://obsproject.com/logs/cGfkBclwG4JMzIeP

Expected Behavior

No crash or settings corruption should occur.

Current Behavior

When calling CreateScene via the Websocket API using the name of the previously active scene that has just been deleted, a fatal crash occurs. Then further crashes occur on OBS startup until the %APPDATA%/basic settings directory is deleted.

Steps to Reproduce

  1. Create a new Scene via the Websocket API (CreateScene)
  2. Make the newly created scene the active scene via the API (SetCurrentProgramScene)
  3. Remove All Scenes via the Websocket API (GetSceneList -> RemoveScene)
  4. Create a new scene using the same name used in (1) via the Websocket API (CreateScene)

I've got a minimal golang program that reporduces this issue below, hopefully that is all you need to reproduce this.

package main

import (
	"fmt"
	"github.com/andreykaipov/goobs"
	"github.com/andreykaipov/goobs/api/requests/scenes"
)

const (
	ServerURI      = "127.0.0.1:4455"
	ServerPassword = ""
	SceneName      = "TestScene"
)

func main() {
	client, err := goobs.New(ServerURI, goobs.WithPassword(ServerPassword))
	if err != nil {
		panic(err)
	}
	
	err = CreateScene(client, SceneName)
	if err != nil {
		panic(err)
	}

	err = SwitchToScene(client, SceneName)
	if err != nil {
		panic(err)
	}

	err = RemoveAllScenes(client)
	if err != nil {
		panic(err)
	}

	_ = CreateScene(client, SceneName)
	fmt.Printf("Crash should have occured post-request")
	return
}

func CreateScene(client *goobs.Client, sceneName string) error {
	_, err := client.Scenes.CreateScene(&scenes.CreateSceneParams{
		SceneName: &sceneName,
	})
	return err
}

func SwitchToScene(client *goobs.Client, sceneName string) error {
	_, err := client.Scenes.SetCurrentProgramScene(&scenes.SetCurrentProgramSceneParams{
		SceneName: &sceneName,
	})
	return err
}

func RemoveAllScenes(client *goobs.Client) error {
	sceneList, err := client.Scenes.GetSceneList()
	if err != nil {
		return err
	}

	for _, scene := range sceneList.Scenes {
		_, err := client.Scenes.RemoveScene(&scenes.RemoveSceneParams{
			SceneName: &scene.SceneName,
		})
		if err != nil {
			return err
		}
	}

	return nil
}

Anything else we should know?

No response

timmaclean avatar Apr 14 '24 06:04 timmaclean

FYI, I have reported a separate but similar bug to this one ( https://github.com/obsproject/obs-studio/issues/10532 ). I'm mentioning it as they may share a common underlying cause.

timmaclean avatar Apr 14 '24 06:04 timmaclean

A comment in the other bug report I submitted (https://github.com/obsproject/obs-studio/issues/10532#issuecomment-2054085464) suggested adding a delay after calling RemoveScene, to determine if a race condition was occurring.

While it had no impact in that issue, when applying a 500ms delay to the call in this issue it resulted in the crash no longer occurring, and the final CreateScene call works as expected.

timmaclean avatar Apr 15 '24 07:04 timmaclean

Having a similar issue via the websocket API on MacOS

Glitched avatar May 17 '24 02:05 Glitched