A bit off topic.-----------------------------
Hi,
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.
This problem happen on a slackware 8.1 with gcc 2.9.5 (I don’t know the
version of the pthread)
I have tested the code below on a Red Hat 8 (psyche) with gcc-3.2 and
pthread 0.10, and it works.
Does anybody has already encounter such an error ? Is there special
compilation option ? I would like to fix this, otherwise my game won’t work
on all linux box. I also hope that I musn’t force people to compile with a
special version of the pthread library or gcc.
I will try with gcc-3.2 ans my current pthread tonight.
thanks
Julien
#include <SDL.h>
class Mask {
public :
Mask (unsigned int width=32, unsigned int height=32);
~Mask ();
bool test();
private:
unsigned char * _mask;
};
class Juju {
public:
Juju();
void foo();
private:
Mask * m;
};
Mask :: Mask (unsigned int width, unsigned int height)
{
_mask = new unsigned char[10000];
}
Mask :: ~Mask() {}
bool
Mask :: test()
{
return 0;
}
Juju:: Juju()
{
m = new Mask(32,32);
}
void
Juju:: foo()
{
m->test();
}
int main(int argc, char** argv)
{
Juju juju;
juju.foo();
}