ocornut / imgui_test_engine

Dear ImGui Automation Engine & Test Suite
386 stars 40 forks source link

Compilation error on Windows GCC/MingW because code uses try-except statement #23

Closed aandrejevas closed 1 year ago

aandrejevas commented 1 year ago

image Hello, I am getting this error when compiling my app with gcc. So try-except statement is a Microsoft extension that gcc does not seem to support.

image The try-except statement is used in function ImThreadSetCurrentThreadDescriptionWin32OldStyle which is defined in file imgui_te_utils.cpp.

I suggest changing the test to #ifdef _MSC_VER so that the function would be excluded when compiling with gcc. This function is used only one time in function ImThreadSetCurrentThreadDescription, there also the usage of the problematic function should be conditional. After I added my proposed changes I was able to compile and run my app.

ocornut commented 1 year ago

Hello,

I believe on your setup we should be using <pthread.h> + pthread_setname_np().

Can you confirm if it works with the following?

#if defined(__linux) || defined(__linux__) || defined(__MACH__) || defined(__MSL__) || defined(__MINGW32__)
#include <pthread.h>    // pthread_setname_np()
#endif

If it works I'll add the proper fix.

aandrejevas commented 1 year ago

Yes, with those changes everything works. I added || defined(__MINGW32__), then I deleted ImThreadSetCurrentThreadDescriptionWin32OldStyle() function definition and removed the call to that function. Then I replaced that call with pthread_setname_np(pthread_self(), description);.

ocornut commented 1 year ago

Thank you for confirming! Pushed 51c554a!