LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Very wierd Segmentation Fault (https://www.linuxquestions.org/questions/programming-9/very-wierd-segmentation-fault-202666/)

The_Nerd 07-08-2004 01:36 PM

Very wierd Segmentation Fault
 
My code is very large so I am not going to post it here. I will just try to explain the best I can.

My C++ program:

I have an Image class that Loads images and Binds them to OpenGL image objects. If there is already an image loaded for the current class it will free it and then load the new image. I have a function called New that takes 3 perameters: Width, Height, and Bpp. It frees already used data, and resizes the image.

I am trying to integrate Python into my program via Python C/Api. I made/am making a wrapper class in python for my Image class. I can get and set all the variables in the Image class. But when I call New(Width, Height, Bpp) from Python it causes a SEGV.

I tracked it down to the New member call in my program... Kinda.

It goes something like this:

Code:

PyObject *Py_Image_New(PyObject *Self, PyObject *Args)
{
    //Get args
    returnValue=(typcast(Self))->New(Width, Height, Bpp);
    return PyBuildObject("i",returnValue);
}

This causes a Segmentation fault. However, the call to New finishes succefully.

This is where it gets hairy:
If I put a fprintf(stderr, "Something\n"); after the call to New, then my program runs fine without any problems!

I tried using DDD to debug it, but I can't track anything because Python calls my function via a pointer, so DDD can't track it.

Why would a simple call to fprint fix a SEGV?
What am I doing wrong?

Mara 07-08-2004 05:14 PM

There must be something wrong, not neccesary at this point. I'd suggest to run valgrind on your program. It'll find all memory allocation - related problems in your program. Warning: output may be very long! It saved me much time when dealing which strange segfaults.

The_Nerd 07-11-2004 01:53 AM

Just incase anyone is interested:

I was getting the SEGV by doing the following:

unsigned short Width, Height, Bpp;

Py_ParseTuple(Args, "III", &Width, &Height, &Bpp);

But I looked a little closer in the Python docs and I found that I is for unsigned int not unsigned short

It works great now that I use H...

I wonder why a printf fixed it though? :confused:


All times are GMT -5. The time now is 06:23 AM.