-
Notifications
You must be signed in to change notification settings - Fork 271
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
Crash in _rmt_UnbindOpenGL #161
Comments
Following the code that seems rather impossible as the OpenGL sample tree is destroyed during unbind. It's then recreated on the next sample push. Do you have any outstanding sample begin/end calls that haven't closed before the unbind? |
There is only one thread that does OpenGL related calls do Remotery, so when unbind is called there is definitely no OpenGL related sampling being done anymore. It IS in theory possible that non-OpenGL related sampling is still being done when OpenGL unbind is called. Could that be a problem? Also, do I HAVE to make the unbind/bind opengl remotery calls on the same thread that does the render sampling, or can I do it from any thread? |
Unbind, at least, has to be called from the same thread that issues the samples. This is because each sample allocates an OpenGL query. When you unbind those queries are released and calling into the OpenGL API from multiple threads on the same context is undefined behaviour. When I mean outstanding samples, sometimes this can happens:
It's the only thing I can think of right now but I've only given the code a cursory glance. I'll to a deeper walk through it later and maybe setup a test case. |
Nope absolutely no OpenGL sampling going on. I'm debugging it a bit. When I step into FreePendingSampleTrees the second time round, it gets into the while (data < dat_end) loop. On line 5518 (my code) it gets the sample tree from the payload:
This sample_tree has 3 members, root_sample, allocator and thread_name. The second two look perfectly fine in the debugger, but the root_sample points to deleted memory. Literally every member in that root_sample has 0xdddddddddd as its value, MSVC's way of telling you the memory was freed. Hope this helps. |
Did a little more research, the values in the sample_tree can become pretty much anything. I sprinkled the code with IsBadReadPtr checks on Windows, got random hits on that during the second UnbindOpenGL -> FreePendingSampleTrees call everywhere. |
OK, got a repro here:
Compiles with:
|
I am using:
I build remotery (and the rest of my code) statically with the following defines:
There are two scenarios.
SCENARIO 1:
This works fine.
SCENARIO 2:
In this scenario the crash happens.
In this second scenario, the crash happens in the second rmt_UnbindOpenGL call in step 4, which is the second time I'm calling it. The call relevant callstack is short:
This is in the following code:
The exception thrown is on the line marked "// CRASH HERE (!!!)"
According to the debugger, the Sample* sample variable going in is 0xdddddddddddddddd, indicating the memory was already freed.
It seems somehow rmt_UnbindOpenGL doesn't expect to be called more than once?
The text was updated successfully, but these errors were encountered: