Re: segmentation fault when window closes



Hi Piscium,

On Wed, 22 Sep 2010 23:14:20 +0100 you wrote:
> I created a example program to summarize the relevant details of my
> application. It is listed below. Interestingly the example does _not_
> crash. But I must be doing something wrong, and the fact that the
> example does not crash must be a coincidence. 

No, that's a very unsafe assumption. If your application crashes when
your example doesn't, then the most likely explanation is that the
problem lies in something where the application differs from the
example. 

That said, it may be as simple as the application does enough extra
work that it overwrites the freed up stack space in which your "Object"
instances were created. When you create "o" you do so on the stack. You
then "push_back" onto the std::vector. This does create a copy, but you
have not defined a copy-constructor for your "Object" class, so that
copy operation is uncontrolled. It will be a raw binary copy, and will
not invoke the ustring copy-constructor.

It may be enough to overload your existing Object(int, char*) with a
version that takes a ustring, but it's better to explicitly define 

Object::Object ( Object o )
{
	id = o.id;
	name = o.name;
}

I can't promise that will work, but it ought to help. BTW, this is all
fairly basic C++ and not GTKmm related; this probably isn't the best
place to be asking.

Cheers,
Rob


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]