Encountering Segfault on Set Background Color of window

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
guzmanpaco
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Aug 18, 2021 1:02 am

Encountering Segfault on Set Background Color of window

Post by guzmanpaco »

Hi

So my software has a button that does computation in the background while updating a window's background color and enabling/disabling buttons.

My problem is it randomly crashes on Mac and Windows like 2/100 times. Based on trace, it crashes on IsOK function of wxWindow.

On code, the thread:

1. I removed all yield
2. I moved all UI changing to Bind(wxEVT_THREAD, &MyClass::OnMessage, this) so that it would be executed in Main Thread.

It usually crashes on the line where I set the background color (It gets code 11 segfault on the IsOK function that is called by SetBackgroundColor). The background color is a static wxColor variable. So I don't think it's the variable's fault. The window is declared as a pointer that was initialized and there is null checking performed before setting background color.

Is there any other possible cause for the crash? I am using wxWidgets 3.1.5 and can replicate using wxWidgets 3.1.7. I did not encounter this in 3.1.0
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Encountering Segfault on Set Background Color of window

Post by ONEEYEMAN »

Hi,
Did you declare that static variable or you are using some predefined color?
Can we see a backtrace at the time of the crash?
And can you post some code on what you are doing with the thread handler.

And finally are you sure you got rid of all GUI calls inside the thread?

Thank you.
guzmanpaco
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Aug 18, 2021 1:02 am

Re: Encountering Segfault on Set Background Color of window

Post by guzmanpaco »

Hi.

I am using a pre-defined color.

My current workaround is to leave setting of background in the thread. If it's in onMessage, it encounters that issue on Mac.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Encountering Segfault on Set Background Color of window

Post by ONEEYEMAN »

Hi,
DO NOT DO ANYTHING GUI RELATED IN THE SECONDARY THREAD!!!!!!!!!

GUI classes are not three safe.

Now you didn't post any code and no backtrace? Is it something proprietary?

Thank you.
Post Reply