[SDL] Problem with threads and new in C++

Joby Bednar thebigcheese at jobybednar.com
Thu Jan 30 10:54:03 PST 2003

If you overload the constructor for Mask to allow for Mask() and Mask(w,h), do you still have the problem?

Rather than Juju having Mask as a member, you might want to try having Juju inherite Mask.  The relationship of Juju and Mask might get a little sketchy with juju creating m with no constructor being used and juju's constructor creating another Mask object and assigning it to m.  Perhaps the different results you've seen in the corruption is the order of object creation and such that could also relate to threading.  You might want to try adjusting this relationship so either a 0 argument constructor exists for Mask, or have Juju inherite Mask as an object.

- Joby
Give someone a program - frustrate them for a day.
Teach them how to program - frustrate them for a lifetime.

---------- Original Message ----------------------------------
From: Sam Lantinga <slouken at devolution.com>
Reply-To: sdl at libsdl.org
Date:  Thu, 30 Jan 2003 07:31:10 -0800

>> I found a strange bug, when I was programming my game with SDL. I join at
>> the end of the message a basic example that reproduce it. The problem is
>> that the "this" pointer of the object "m" has wrong value during the call to
>> "m->test" in the method "Juju :: foo()". When I put a breakpoint in the
>> "test" method, then run and  do a backtrace I can see that the "this"
>> pointer is corrupted. Usually its value is 0x1. If I don't link with the
>> pthread library, it doesn't happens. But I must link with pthread since I am
>> using SDL. I also find that if I replace the new by a malloc, the problem
>> doesn't occur. The value is also correct if i declare a Mask and not a "Mask
>> *"  in the class Juju, but i don't want to do this.
>You have memory corruption somewhere in your program.
>It sounds like something is writing over the end of an array.
>See ya,
>	-Sam Lantinga, Software Engineer, Blizzard Entertainment
>SDL mailing list
>SDL at libsdl.org

More information about the SDL mailing list