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

AttachToActiveGLContext Crashed in Windows #489

Open
HW140701 opened this issue Jun 20, 2024 · 25 comments
Open

AttachToActiveGLContext Crashed in Windows #489

HW140701 opened this issue Jun 20, 2024 · 25 comments

Comments

@HW140701
Copy link

I have created an OpenGL context in the main window through other methods. When I use AttachToActiveGLContext to bind the current default context, my demo crashes directly, outputting: User-defined allocator is not provided. Using default allocator. Then there is no other output and it crashes directly.

I guess the created OpenGL context is being used by another thread, and then the crash occurs when the context is bound using AttachToActiveGLContext?

  • OS and version you are running:Windows 10 19045.3930
  • Build tools and configuration you used to build the engine: (e.g. Visual Studio 2019 Debug x64 + CMake 3.29.5)
  • GPU and driver version you have installed on your system :NVIDIA 1060 6G,4.6.0 NVIDIA 552.44
  • Debug output, especially messages from Diligent:User-defined allocator is not provided. Using default allocator.
@TheMostDiligent
Copy link
Contributor

The context must be active in the thread when you call AttachToActiveGLContext.
If you use the context in multiple threads, the context must always be active in the thread whenever you call any Diligent function.

@HW140701
Copy link
Author

Thanks for you reply.
Is there any way to avoid the crash? How can I make AttachToActiveGLContext not crash immediately when the context is not active?

@TheMostDiligent
Copy link
Contributor

Where exactly does the crash happen?
What is the call stack?

@HW140701
Copy link
Author

“User-defined allocator is not provided. Using default allocator.” is the last output and then the program is crash.
The crash code maybe in:
image

@TheMostDiligent
Copy link
Contributor

What is the call stack?
Did you build Debug configuration?

@HW140701
Copy link
Author

this is my call stack.
image

this is my code to use AttachToActiveGLContext when have no window handle.
image

@TheMostDiligent
Copy link
Contributor

Did you initialize OpenGL context before calling AttachToActiveGLContext?
Where inside the AttachToActiveGLContext function does it crash?

@HW140701
Copy link
Author

yes,I am not sure whether initialize OpenGL context before calling AttachToActiveGLContext,because the previous part is not my responsibility, is it important to have no initial opengl context?

The program executes SetRawAllocator because output “User-defined allocator is not provided. Using default allocator.”,then crash,I can only judge by the logs.
image

@TheMostDiligent
Copy link
Contributor

If you don't have active GL context that you initialized, you should not be calling AttachToActiveGLContext.
Use CreateDeviceAndSwapChainGL

@HW140701
Copy link
Author

CreateDeviceAndSwapChainGL need the window handle parameter.
Calling AttachToActiveGLContext must surely crash if there is no active context?

@TheMostDiligent
Copy link
Contributor

CreateDeviceAndSwapChainGL need the window handle parameter

Yes, you need Window handle to create the OpenGL context on Windows.

Calling AttachToActiveGLContext must surely crash if there is no active context?

If there is no active context, you should not be calling this function.

Please take a look at the example I sent.

@HW140701
Copy link
Author

ok, thanks for your replay.
Is there any good way to determine whether there is an active context?

@TheMostDiligent
Copy link
Contributor

https://registry.khronos.org/EGL/sdk/docs/man/html/eglGetCurrentContext.xhtml

If you did not initialize a context, there is definitely no context.

@HW140701
Copy link
Author

thanks for your reply

@HW140701
Copy link
Author

Is there any way in Diligent Core or Diligent Engine to get the current context?

@TheMostDiligent
Copy link
Contributor

TheMostDiligent commented Jun 20, 2024

I don't completely understand the question.
On Windows, it uses the wglGetCurrentContext
If there is none, it returns an error

@HW140701
Copy link
Author

thanks

@HW140701
Copy link
Author

HW140701 commented Jul 1, 2024

hello, I caught this crash code through the pdb file.

image

It seems that there is a problem when allocating memory. But I don't understand where the problem is. Can you find out where the problem is?

@TheMostDiligent
Copy link
Contributor

Is this related to AttachToActiveGLContext?

@HW140701
Copy link
Author

HW140701 commented Jul 2, 2024

Yes, the problem occurs when calling AttachToActiveGLContext, more precisely in the following line.
image
m_AddrToPageId is a std::unordered_map, and I find it weird that the reserve function of std::unordered_map crashes.

@TheMostDiligent
Copy link
Contributor

Can you build a reproducer based on one of the Tutorials? Tutorial00_HelloWin32 in particular?

@HW140701
Copy link
Author

HW140701 commented Jul 2, 2024

After extensive testing, we found the GPU that causes the crash: [AMD Radeon HD 8670M].

@TheMostDiligent
Copy link
Contributor

What was the issue with this GPU?
The crash on the allocator is still quite strange

@HW140701
Copy link
Author

HW140701 commented Jul 2, 2024

When using AttachToActiveGLContext on this GPU, it crashes immediately.
I am also very troubled by this error, and in my mind, the C++ standard library is generally not a problem.

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

2 participants