New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g_object_remove_toggle_ref: couldn't find toggle ref #220

Closed
gnunn1 opened this Issue Nov 18, 2017 · 14 comments

Comments

Projects
None yet
3 participants
@gnunn1
Contributor

gnunn1 commented Nov 18, 2017

I have users reporting a crash bug in tilix (gnunn1/tilix#1192) with reports of a warning as per below with tilix and the current release of GtkD. While I don't think this is causing the crash issue, I tend want to report the warning.

The warning seems to be related to using Scoped! with parameters. If you look at the Application.d code that handles the command line (https://github.com/gnunn1/tilix/blob/master/source/gx/tilix/application.d#L381) I switched to using the Scoped! version of this method awhile ago. However it's now emitting the following warning:

GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref 0x561ca0ca1800(0x7fffdb9e4500)

If I revert the change to use the non Scoped version and manually destroy the command line it works as expected.

@MikeWey

This comment has been minimized.

Member

MikeWey commented Nov 18, 2017

It looks like the value of this changes between the constructor and the destructor when using Scoped.

The warning shouldn't case a crash, but if the destroyNofify or toggleNotify callbacks are triggered for ApplicationCommandline they probably receive an invalid pointer as their user data.

A minimal test case:

import gio.Application;
import gio.ApplicationCommandLine;

int main(string[] args)
{
	int onCommandLine(Scoped!ApplicationCommandLine acl, Application) {
		return 0;
	}

	auto application = new Application("org.gtkd.test.commandline", ApplicationFlags.HANDLES_COMMAND_LINE);
	application.addOnCommandLine(&onCommandLine);
	return application.run(args);
}
@MikeWey

This comment has been minimized.

Member

MikeWey commented Nov 19, 2017

this changes because Scoped stores the class on the stack, and we are passing it as a function parameter which moves the Scoped struct.

MikeWey added a commit that referenced this issue Nov 19, 2017

Use our own version of Scoped to avoid issues with `this`.
Th Scoped in phobos allocates the payload on the stack. And we pass the
Scoped struct from the callback to the delegate, this moves the Scoped
struct changing the value of `this`.

This causes problems with add/remove toggle_ref in the constructor and
destructor, because the value of the data passed should match in both
calls. And the callbacks used by ObjectG will receive a pointer to the
object before it was moved.

See also: #220
@MikeWey

This comment has been minimized.

Member

MikeWey commented Nov 19, 2017

990e1f8 fixes the issue with remove_toggle_ref, i don't know if it helps with the crash.

@MikeWey

This comment has been minimized.

Member

MikeWey commented Nov 24, 2017

I tried to check if the crash from gnunn1/tilix#1192 was related to the toggle ref warning, but i can't seen to reproduce the crash when building tilix with 3.7.1.

@gnunn1

This comment has been minimized.

Contributor

gnunn1 commented Nov 25, 2017

I cannot reproduce it either unfortunately. I've removed the three places where Scoped! was used and am manually destroying the Context/CommandLine instead. This is just so people can test to see if it helps with the issue at all.

@gnunn1

This comment has been minimized.

Contributor

gnunn1 commented Nov 26, 2017

I think I found the issue, but I'm not sure why it is causing the problem. I link in the function gdk_x11_get_server_time using the GtkD linker dynamically. If I comment out linking in the function, everything works fine. However if I link the function into tilix, it fails with a segfault. Weirdly, this has been part of tilix for a long time now so I'm not sure why it is failing now.

Don't spend any time investigating, bit if you have any thoughts based on your experience I'd appreciate it. The code in question is here:

https://github.com/gnunn1/tilix/blob/master/source/gx/gtk/x11.d#L87

@MikeWey

This comment has been minimized.

Member

MikeWey commented Nov 26, 2017

I don't have any ideas for why that would fail.

I've tagged v3.7.2 with the fix for the toggle_ref warning and the possible issues with the callbacks.

@MikeWey MikeWey closed this Nov 26, 2017

@gnunn1

This comment has been minimized.

Contributor

gnunn1 commented Nov 26, 2017

Thanks as always.

@Aphexus

This comment has been minimized.

Aphexus commented May 25, 2018

GLib-GObject-WARNING **: g_object_remove_toggle_ref: couldn't find toggle ref

I'm also getting this warning constantly in x64 build but it does not show up in x86. I have not yet investigated as I just saw it and this was the first link on searching. Being an x64 issue

... ref 00007ff72d090510(0000021b5235fe40)

... 00007ff72d090510(0000021b5235xxxx)

the xxxx part increments. Seems that it is scanning an array.

Maybe there is an invalid x86 cast(why the upper part is 0)? If this is a size_t type of issue then I'd make sure that the casting is correct in all uses since it might be used in other places. (may be a general architecture mistake)

The errors happen at startup and I haven't checked the program usage in x64 yet to see any other issues.

@MikeWey

This comment has been minimized.

Member

MikeWey commented May 25, 2018

If the error is on the D side it's most probably a double free error.

Are you using Windows 64 by any chance?

@Aphexus

This comment has been minimized.

Aphexus commented May 25, 2018

Yes, I should have mentioned that. Are you saying that I am freeing the object twice somewhere? If so, would I not get that error in x86 also? I have no idea yet what the warning is related to in my code since it offers no information(is it possible for the errors to post more information such as source and line number where they originate and/or a stack trace?).

@MikeWey

This comment has been minimized.

Member

MikeWey commented May 26, 2018

The D gc handles the memory for you, and GtkD should handle the reference counting of the Gtk objects. But there have been issues with GtkD where we would remove the toggle reference more then once resulting in the error.

Could you check if you still experience the error with commit: 7e0471a

@MikeWey MikeWey reopened this May 26, 2018

@Aphexus

This comment has been minimized.

Aphexus commented May 26, 2018

From what little testing, that seemed to fix it! Thanks! I'll report back if it happens again.

@MikeWey

This comment has been minimized.

Member

MikeWey commented May 27, 2018

Great.

@MikeWey MikeWey closed this May 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment