ocornut/imgui_test_engine

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

aandrejevas opened this issue · 3 comments

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.

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
  • remove ImThreadSetCurrentThreadDescriptionWin32OldStyle()
  • simply call pthread_setname_np(pthread_self(), description); in ImThreadSetCurrentThreadDescription() ?

If it works I'll add the proper fix.

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);.

Thank you for confirming! Pushed 51c554a!