Bug? wxGrid + Debug + Linux

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
Mr-T
Experienced Solver
Experienced Solver
Posts: 58
Joined: Thu Mar 31, 2022 11:30 pm

Bug? wxGrid + Debug + Linux

Post by Mr-T »

Not sure, but it seems I stumble over a bug in combination with wxGrid + Linux with enabled Debug.

What Happens:

- I close my application an get the message: "../src/common/object.cpp(336): assert "m_count > 0" failed in DecRef(): invalid ref data count"

More Details:

- I wrote an application with my own wxGrid implementation (inherited) to support some special Insert/Delete/... features.
- The app uses the AUI-Manager to show exactly 3 Custom-wxGrid-windows (2 with it's own Renderer) and also 1 wxPropertyGridManager.
- I compile the application against wxWidgets 3.1.5 (the official-inofficial "gtk3-unicode-3.1-unofficial" variant for Ubuntu 20 and also cross-compile it for Windows (wxWidgets 3.1.5 + 3.1.6 --- cross compiled by myself).

What I have observed:

- The exactly same application-source compiled for Windows (wxWidgets 3.1.5 & 3.1.6) as Debug and Release version run without any problem.
- The compiled application for Linux as Release is working, as Debug version - the above message occurs with a segmentation fault.
- After searching for the cause, I found that
--- the Windows-Variant always sets the focus to the first wxGrid table
--- if I start the Linux-Variant, no cell is focused, if I click on any cell (to get the focus) - I can close the application without crash
--- if I insert the call "SetFoucs()" into my code for the first wxGrid - than the problem not occurs, seems to be fixed
--- If I compile with everything exactly (Debug-Settings that crash), but add the option "-DNDEBUG" the issue is gone, too


Some ideas?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bug? wxGrid + Debug + Linux

Post by doublemax »

Based on the assert message, it seems obvious that there is an error in your code regarding reference counting. If you check the wxGrid documentation, you'll see several methods that say "The caller must call DecRef() on the returned pointer.". I guess you didn't do that everywhere where it's needed.
If I compile with everything exactly (Debug-Settings that crash), but add the option "-DNDEBUG" the issue is gone, too
This will just disable the assert, the bug is still there.
Use the source, Luke!
Mr-T
Experienced Solver
Experienced Solver
Posts: 58
Joined: Thu Mar 31, 2022 11:30 pm

Re: Bug? wxGrid + Debug + Linux

Post by Mr-T »

That's right, I found also an other Forum thread with the same issue about the "DecRef()" ... something about the the attributes. But I don't touch them anywhere.

The reason why I'am think it could be also something other is, a SetFocus() call fix the issue too and or just selecting a cell.
- Does the SetFocus touch any reference counter?
- Should the windows application (Debug-variant) not crash also?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bug? wxGrid + Debug + Linux

Post by doublemax »

The first step should be to get a backtrace/call stack from the assert and check which object caused it. This should narrow it down.
Use the source, Luke!
Mr-T
Experienced Solver
Experienced Solver
Posts: 58
Joined: Thu Mar 31, 2022 11:30 pm

Re: Bug? wxGrid + Debug + Linux

Post by Mr-T »

You have right, I believe I found the problem. Looks like the garbage-management failed because of multiple use of an object.

In Detail: I used the "same" instance of my own wxGridCellRenderer for 2 tables at the same time.

Fix: Add an "IncRef()" before use of the Renderer a second time.


--

But, the open question for me, why a SetFocus also helps, too?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bug? wxGrid + Debug + Linux

Post by doublemax »

Mr-T wrote: Thu Apr 28, 2022 9:53 pm But, the open question for me, why a SetFocus also helps, too?
No idea. Probably some weird side-effect. You'd have to check what operations on the grid are executed because of that call. I'm sure there is a logical explanation, but i'm not sure if it's worth the effort to track it down.
Use the source, Luke!
Post Reply