Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sporadic panics due to RegisterClassExA failures #158

Open
mwilliamson-fourier opened this issue Jul 2, 2024 · 0 comments
Open

Sporadic panics due to RegisterClassExA failures #158

mwilliamson-fourier opened this issue Jul 2, 2024 · 0 comments

Comments

@mwilliamson-fourier
Copy link

Hello! We've been using nih-plug in some of our tests, and we've noticed sporadic failures due to this assertion failing:

assert_ne!(unsafe { RegisterClassExA(&class) }, 0);

implying that the call to RegisterClassExA() is failing. A few lines above, the class name is generated based on the return value from QueryPerformanceCounter():

// Window classes need to have unique names or else multiple plugins loaded into the same
// process will end up calling the other plugin's callbacks
let mut ticks = 0i64;
assert!(unsafe { QueryPerformanceCounter(&mut ticks).as_bool() });
let class_name = CString::new(format!("nih-event-loop-{ticks}"))
.expect("Where did these null bytes come from?");

Since Rust tests are run in parallel by default, I believe the issue is that two threads are attempting to create a class at the same time, resulting in the same class name being generated and therefore and the call to RegisterClassExA() failing in one of the threads. That would also explain why we only see the error occasionally: most of the time, the two threads happen to get different values from QueryPerformanceCounter().

Assuming that is the case, I think this could be fixed by changing how the class name is generated, for instance by including the thread ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant