LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2004, 01:36 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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?
 
Old 07-08-2004, 05:14 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 07-11-2004, 01:53 AM   #3
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
segmentation fault lmvent Programming 2 10-20-2005 03:14 PM
ls segmentation fault sucho Linux - General 1 06-23-2004 06:44 PM
segmentation fault... perdesiz Linux - Software 1 08-18-2003 01:55 AM
Segmentation Fault live2 Linux - General 6 03-02-2003 08:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration