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

Globals initialization order failure with opencv #2884

Closed
egorpugin opened this issue Aug 22, 2020 · 5 comments
Closed

Globals initialization order failure with opencv #2884

egorpugin opened this issue Aug 22, 2020 · 5 comments
Assignees

Comments

@egorpugin
Copy link
Contributor

See opencv/opencv#18166

@mloskot
Copy link
Member

mloskot commented Aug 22, 2020

[gdal-dev] Exception in GDALAllRegister() thread seems related.

If you have a specific error report to GDAL, fill it in, otherwise this should be closed, I think.

@egorpugin
Copy link
Contributor Author

Do you have an issue for that thread?
Anyways feel free to close as duplicate.

@mloskot
Copy link
Member

mloskot commented Aug 22, 2020

Do you have an issue for that thread?

No. OP has never opened one providing us with his "empty" test application as reproducible minimal example, so we can "experience [similar] a crash in GDALAllRegister" as you can read in OP's posts.

The final report was:

Changing both to /MDd doesn't seem to make a difference - the same fatal exception occurs

which to me seems fishy as there are hundreds of such GDAL clients built on Windows in the wild,
including myself building and running GDAL clients (all built w/ /MD[d]) on daily/weekly basis for ~15 years
without observing such problem.
So, I suspect the problem was due to some build configuration/API misuse issue.

In case of static libraries (i.e. /MT[d]) situation may be different and prone to random static initialisation fiasco indeed, but we still need a Minimal Working Example with details on build configuration in order to reproduce the problem.

@egorpugin
Copy link
Contributor Author

It's easy enough.
The issue is because of linking order. (Do not remember .obj files into .lib or even .lib files into .exe).
MSVC does not have specific init order. It's undefined. I saw such issues several times (qt - said wontfix, some other libs with globals).

Possible solution from my pov is to make wrapper auto f() {static x ...; return x;}. Tried this approach in my project (~2y ago), new issue is that it's hard to set destruction order correctly. I came to solution to maintain global library state or context with all globals moved into this structure or something similar. Works good.

@mloskot
Copy link
Member

mloskot commented Aug 22, 2020

It's easy enough.
(...)
Possible solution from my pov is to make wrapper (...)

Feel free to submit PR with a fix in C++11.

@rouault rouault self-assigned this Feb 19, 2024
rouault added a commit that referenced this issue Feb 26, 2024
VRTDerivedRasterBand: avoid potential initialization order fiasco (fixes #2884)
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

3 participants