obs-teleport
obs-teleport copied to clipboard
M1 arm64 deadlock
Looks like interacting with the the frontend API is deadlocking/crashing OBS.
Can be reproduced with the following plugin:
package main
// #include <obs-module.h>
// #include <obs-frontend-api.h>
//
// extern void frontend_event_cb(enum obs_frontend_event event, void* data);
//
import "C"
import (
"log"
"unsafe"
)
var obsModulePointer *C.obs_module_t
//export obs_module_set_pointer
func obs_module_set_pointer(module *C.obs_module_t) {
obsModulePointer = module
}
//export obs_current_module
func obs_current_module() *C.obs_module_t {
return obsModulePointer
}
//export obs_module_ver
func obs_module_ver() C.uint32_t {
return C.LIBOBS_API_VER
}
//export frontend_event_cb
func frontend_event_cb(event C.enum_obs_frontend_event, data unsafe.Pointer) {
log.Println("event:", event)
}
//export obs_module_load
func obs_module_load() C.bool {
C.obs_frontend_add_event_callback(C.obs_frontend_event_cb(unsafe.Pointer(C.frontend_event_cb)), nil)
return true
}
func main() {}
Could be a Go runtime issue when using cgo. But I have no idea..
Process 2159 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x000000013fe00634 obs-test.so`notok + 4
obs-test.so`notok:
-> 0x13fe00634 <+4>: str x8, [x8]
0x13fe00638 <+8>: b 0x13fe00638 ; <+8>
0x13fe0063c <+12>: udf #0x0
obs-test.so`runtime.open_trampoline.abi0:
0x13fe00640 <+0>: str x30, [sp, #-0x10]!
Target 0: (OBS) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x000000013fe00634 obs-test.so`notok + 4
frame #1: 0x000000013fe00c30 obs-test.so`runtime.sigaltstack_trampoline.abi0 + 32
frame #2: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200
frame #3: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200
frame #4: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200
I also believe I am running into this on OBS 28 beta 2 on an M1 mini.
I wonder if anyone with a beta of macOS Ventura wants to check if the issue persists.
I tried it. OBS will not start after installing the plugin(obs-teleport.plugin).
macOS Ventura 13.0 Beta OBS 28.0.1 arm64
Thanks for checking. It does not take us much further - but is a good piece of information.
A custom build of OBS with enabled Address-Sanitizer
loads the plugin just fine. Without the sanitizer the same crash as above happens.
Things are getting wild. With this OBS patch applied it seems to run fine:
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3055,6 +3055,19 @@ void ctrlc_handler(int s)
int main(int argc, char *argv[])
{
+#if defined __APPLE__ && defined __arm64__
+ char signalStack[SIGSTKSZ];
+ stack_t ss;
+ memset(&ss, 0, sizeof(ss));
+ ss.ss_sp = signalStack;
+ ss.ss_flags = 0;
+ ss.ss_size = SIGSTKSZ;
+ if (sigaltstack(&ss, NULL) < 0) {
+ perror("sigaltstack");
+ abort();
+ }
+#endif
+
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
Not sure though whether this breaks any existing signals/signal handlers.
Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 02cf48d6c016a..d1143603f93c0 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3165,13 +3165,28 @@ void ctrlc_handler(int s)
int main(int argc, char *argv[])
{
#ifndef _WIN32
- signal(SIGPIPE, SIG_IGN);
+ stack_t ss;
+ ss.ss_sp = malloc(SIGSTKSZ);
+ if (ss.ss_sp == NULL) {
+ fprintf(stderr, "ss_sp alloc failed\n");
+ exit(1);
+ }
+ ss.ss_size = SIGSTKSZ;
+ ss.ss_flags = 0;
+ if (sigaltstack(&ss, NULL) < 0) {
+ perror("sigaltstack");
+ exit(1);
+ }
struct sigaction sig_handler;
- sig_handler.sa_handler = ctrlc_handler;
+ sig_handler.sa_handler = SIG_IGN;
sigemptyset(&sig_handler.sa_mask);
- sig_handler.sa_flags = 0;
+ sig_handler.sa_flags = SA_ONSTACK;
+
+ sigaction(SIGPIPE, &sig_handler, NULL);
+
+ sig_handler.sa_handler = ctrlc_handler;
sigaction(SIGINT, &sig_handler, NULL);
For everyone trying this out. Please write back your macOS version and hardware configuration, and whether it has been working for you or not. (You didn't have to have the patch applied, I just want to collect information what may be the root cause of the original problem)
When launching OBS 29.0.2 native
with obs-teleport-0.6.1
or 0.6.5
on m1 mac 13.2.1
, OBS bounces in the dock forever and doesn't appear.
Yes, this is what thich ticket is about..
I can start up OBS when I connect a 2nd monitor and close my Macbook Air's lid.
To date (February 20, 2023), the only fully working option for how you can play on a PC and stream through a macbook m1 is: Download the obs version for intel on a macbook m1 and install this plugin (teleport) according to the instructions. Since the teleport didn’t start through the obs version of apple silicon, I found a way out in installing the obs version for intel, which works great on the M1. Good luck to all! And thanks for the great alternative to the buggy NDI. P.S. If you have no sound through the teleport plugin when recording a video / broadcast from the obs, then just add your audio sources through the teleport filter. This link works flawlessly.
Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 02cf48d6c016a..d1143603f93c0 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -3165,13 +3165,28 @@ void ctrlc_handler(int s) int main(int argc, char *argv[]) { #ifndef _WIN32 - signal(SIGPIPE, SIG_IGN); + stack_t ss; + ss.ss_sp = malloc(SIGSTKSZ); + if (ss.ss_sp == NULL) { + fprintf(stderr, "ss_sp alloc failed\n"); + exit(1); + } + ss.ss_size = SIGSTKSZ; + ss.ss_flags = 0; + if (sigaltstack(&ss, NULL) < 0) { + perror("sigaltstack"); + exit(1); + } struct sigaction sig_handler; - sig_handler.sa_handler = ctrlc_handler; + sig_handler.sa_handler = SIG_IGN; sigemptyset(&sig_handler.sa_mask); - sig_handler.sa_flags = 0; + sig_handler.sa_flags = SA_ONSTACK; + + sigaction(SIGPIPE, &sig_handler, NULL); + + sig_handler.sa_handler = ctrlc_handler; sigaction(SIGINT, &sig_handler, NULL);
this worked for me thank you
Hello, how does it look with support for apple silicon? I tried it on my macbook pro with m2 max chip and can't even start obs. I'm really looking forward to a possible fix.
Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 02cf48d6c016a..d1143603f93c0 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -3165,13 +3165,28 @@ void ctrlc_handler(int s) int main(int argc, char *argv[]) { #ifndef _WIN32 - signal(SIGPIPE, SIG_IGN); + stack_t ss; + ss.ss_sp = malloc(SIGSTKSZ); + if (ss.ss_sp == NULL) { + fprintf(stderr, "ss_sp alloc failed\n"); + exit(1); + } + ss.ss_size = SIGSTKSZ; + ss.ss_flags = 0; + if (sigaltstack(&ss, NULL) < 0) { + perror("sigaltstack"); + exit(1); + } struct sigaction sig_handler; - sig_handler.sa_handler = ctrlc_handler; + sig_handler.sa_handler = SIG_IGN; sigemptyset(&sig_handler.sa_mask); - sig_handler.sa_flags = 0; + sig_handler.sa_flags = SA_ONSTACK; + + sigaction(SIGPIPE, &sig_handler, NULL); + + sig_handler.sa_handler = ctrlc_handler; sigaction(SIGINT, &sig_handler, NULL);
Re-rolling this patch for 29.x version.
diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index e0b9d114a..b48a0d11c 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3245,13 +3245,27 @@ void OBSApp::ProcessSigInt(void)
int main(int argc, char *argv[])
{
#ifndef _WIN32
- signal(SIGPIPE, SIG_IGN);
+ stack_t ss;
+ ss.ss_sp = malloc(SIGSTKSZ);
+ if (ss.ss_sp == NULL) {
+ fprintf(stderr, "ss_sp alloc failed\n");
+ exit(1);
+ }
+ ss.ss_size = SIGSTKSZ;
+ ss.ss_flags = 0;
+ if (sigaltstack(&ss, NULL) < 0) {
+ perror("sigaltstack");
+ exit(1);
+ }
struct sigaction sig_handler;
- sig_handler.sa_handler = OBSApp::SigIntSignalHandler;
+ sig_handler.sa_handler = SIG_IGN;
sigemptyset(&sig_handler.sa_mask);
- sig_handler.sa_flags = 0;
+ sig_handler.sa_flags = SA_ONSTACK;
+ sigaction(SIGPIPE, &sig_handler, NULL);
+
+ sig_handler.sa_handler = OBSApp::SigIntSignalHandler;
sigaction(SIGINT, &sig_handler, NULL);
I am on a Mac Studio 2022, M1 Max with 32gb of RAM on MacOS Ventura 13.3.1.
Thanks, I haven't noticed they did some changes in that area.
I have updated the original PR here: ~~https://github.com/obsproject/obs-studio/pull/7973~~
Check the branch here: https://github.com/fzwoch/obs-studio/tree/sigaltstack
Note that I don't expect it to me merged ever.
Apple also does not seem to care about the issue, or they consider it a user-space issue but are not telling.
Thanks, I haven't noticed they did some changes in that area.
I have updated the original PR here: obsproject/obs-studio#7973
Note that I don't expect it to me merged ever.
Apple also does not seem to care about the issue, or they consider it a user-space issue but are not telling.
Does it mean that I have to edit something inside obs?
Sorry for my stupid questions :)
Does it mean that I have to edit something inside obs? Sorry for my stupid questions :)
Yes.
Does it mean that I have to edit something inside obs? Sorry for my stupid questions :)
Yes.
Is there a guide somewhere? I'm not that experienced.
Is there a guide somewhere? I'm not that experienced.
Start here: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Mac
In general you will have to build OBS with the patch in the PR, or the pasted one above applied. It can be quite an en-devour for the inexperienced I guess. But you will have to check OBS guides, or guides for these developer tools in general. It is way out of the scope than I can do here..
Is there a guide somewhere? I'm not that experienced.
Start here: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Mac
In general you will have to build OBS with the patch in the PR, or the pasted one above applied. It can be quite an en-devour for the inexperienced I guess. But you will have to check OBS guides, or guides for these developer tools in general. It is way out of the scope than I can do here..
Agree with this.
If anyone is inexperienced, the Prerequisites
sections at the top of the guide might be confusing.
- If you are new to this, start by installing Homebrew by following the instructions here. You can use that to install the last 2 listed prerequisites: https://brew.sh/
- For xcode, you can download that from the Mac's App Store. If you aren't sure of your Mac version, click the Apple icon at the top left of the screen and then click
About this Mac
. At the time of writing this, you need to at least be on MacOS 12.0. So if the number listed is lower, consider upgrading to MacOS Ventura. - For CMake, you can install it on your system by running
brew install cmake
- For CCache, you can install it on your system by running
brew install ccache
After that, you can follow the first step from the Configuring Build Project
which is cloning the project. Copy the git clone --recursive https://github.com/obsproject/obs-studio.git
command into your terminal and then run cd obs-studio
to go the new directory from git.
Note: It is important that you use the --recursive
flag so that all of the submodules are pulled in too.
Run git fetch origin pull/7973/head:bugfix/7973
to pull in the code from fzwoch's PR and put it into a new local branch named bugfix/7973
.
Run git checkout bugfix/7973
to switch to the new local branch.
After that, you can continue to follow the steps in the official wiki's instructions without any issues.
My only issue when following the guide was that building from the command line did not work in the Build obs-studio
section.
When running xcodebuild -configuration <Debug|Release|RelWithDebInfo|MinSizeRel> -scheme obs-studio -parallelizeTargets -destination "generic/platform=macOS,name=Any Mac"
, I got an error saying:
xcodebuild: error: Unknown build action 'obs-studio'
But to get around that:
- Open the
build_arm64
folder that is generated from runningcmake --preset macos-arm64
. - Open the
obs-studio.xcodeproj
file. - (Optional) If you want the newly generated OBS.app file to go to your Applications folder, click
Product
at the top, thenScheme
and thenChoose Scheme
and then selectinstall
from the list.
I wouldn't mind sharing the build I created, but I'm not sure if that is against the rules or anything.
There is also a CI/build-macos.sh
script that does the right thing sometimes..
@andrewmriv can you share ?
There is also a
CI/build-macos.sh
script that does the right thing sometimes..
Hello, what script do you mean?
It has been removed in the meantime from the OBS repository. Check with the OBS team on how to build OBS for macOS.
Same problem, this was my last outing, I hate NDI, I'm going to get a capture card at once:
MAC M1, 2020 - Ventura 13.5
OBS 29.0.2 (64 bit)
Is this change being pushed to the OBS branch? I would like to see a work around that does not require people to manually build both OBS and the plugin. I am switching to MacOS for streaming and could really use this plugin.
I tried getting a fix upstream, but i ran again into issues when trying to remove the signal stack and restoring the old one on exit. Then I hit another documentaion issue on Apple's side and I gave up. But anyone can try getting a proper change upstream..
One can do it without patching OBS. It is still annoying though.
- Make sure
System Integrity Protection
isoff
:
% csrutil status
System Integrity Protection status: disabled.
If it is not check https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection?language=objc
- Run
OBS
with loaded address sanitizer:
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib /Applications/OBS.app/Contents/MacOS/OBS
You will have to check what Xcode version you have installed. So you will need an installation of Xcode. Change the directory for the file location where the sanitizer library is found.
Eventually startup fails with something similar to this:
signal 16 received but handler not on signal stack
mp.gsignal stack [0x106d50000 0x106dd0000], mp.g0 stack [0x16afa0000 0x16b79c000], sp=0x114000058768
fatal error: non-Go code set up signal handler without SA_ONSTACK flag
I guess that can happen since the signals are not properly set up now (which the patch does). Just try again, its seems to be working most of the time for me (but only God knows what impacts this behavior).
Not sure why this signal would sometimes be triggered though, and I'm not sure if it can happen again while OBS is running.. someone will find out?