conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.17k stars 974 forks source link

[bug]OpenCV crashes the program on Linux #16840

Open Marijameme opened 1 month ago

Marijameme commented 1 month ago

Describe the bug

Hi there, I'm using opencv library in my project, and I installed it using conan but it started crashing with the error: Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/Yaru/16x16/status/image-missing.png: Fatal error reading PNG image file: Invalid IHDR data (gdk-pixbuf-error-quark, 0) Bail out! Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/Yaru/16x16/status/image-missing.png: Fatal error reading PNG image file: Invalid IHDR data (gdk-pixbuf-error-quark, 0) Aborted Then I installed the library manually and the program is running perfectly fine. Before this, the program would crash just moments after being started, after almost zero interaction with the program. The funny thing is that it doesn't crash always, sometimes (although rarely) it works fine and the library behaves the way it is expected. I didn't do anything fancy with my CMake in order to include the library, just the following

find_package(OpenCV REQUIRED)   
include_directories( ${OpenCV_INCLUDE_DIRS} )    
target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_LIBS})

Environment details

[conf] tools.system.package_manager:mode=install tools.system.package_manager:sudo=True

valgur commented 1 month ago

It looks like the error occurs in GTK and is only tangentially related to OpenCV. I suspect the issue is caused by gtk/system being used and it transitively linking against libpng or something similar.

The only real fix for that would be to use a proper Conan version of GTK, but it's yet to be migrated. Mostly due to a bunch of trivial version conflicts blocking the build:

You can give the updated recipe in that PR or in my personal fork (https://github.com/valgur/conan-center-index) a try.

memsharded commented 1 month ago

Hi @Marijameme

Quick question: did you use pre-compiled binaries from ConanCenter, or are you building them from source? If you installed pre-compiled binaries from ConanCenter, can you please try to build from source forcing it with --build=* and try again?

Also, using:

include_directories( ${OpenCV_INCLUDE_DIRS} )    
target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_LIBS})

Is not recommended in the general case. CMake recommends using targets, so please drop the include_directories() and use the target in target_link_libraries(... PUBLIC opencv_xxxx). Targets might have other extra information, like preprocessor definition, compiler flags, etc.

Marijameme commented 1 month ago

Hi @memsharded, i took your suggestion and built the library from source and made changes to my CMake file but the problem is still there, only less frequent. Also, when it runs I get a warning: Gtk-WARNING **: 18:41:12.072: Could not load a pixbuf from icon theme. This may indicate that pixbuf loaders or the mime database could not be found.

czoido commented 1 month ago

Hi @Marijameme, Which OpenCV version are you using? If your are using some version<4.7.0 could you please check if this issue still happens for a newer version? Like: 4.10.0, 4.9.0 or 4.8.1? Thanks a lot.

Marijameme commented 1 month ago

I tried with 4.10.0 originally, and then with 4.9.0 and 4.5.5, everything was the same.