LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-05-2010, 10:10 AM   #1
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Rep: Reputation: 31
wxPLplotwindow segmentation fault


I've been trying without success to figure out how to use the PLplot wxWidgets driver. The only demo program for this driver that I could find is in the wxPLplot version 0.1 download. (I didn't build the driver from that download -- I'm using the packages from the Debian Lenny and Ubuntu Hardy Heron distributions.)

I couldn't use the makefile included with that demo program because it calls a `plplot-config` script which is not in that download nor in the Debian or Ubuntu distributions but I have been able to compile it using:
Code:
g++ -o demo_str `wx-config --cxxflags --libs` -lplplotcxxd -lplplotwxwidgetsd demo_str.cpp
or
Code:
g++ -o demo_str `wx-config --cxxflags --libs` `pkg-config --cflags --libs plplotd-c++ plplotd-wxwidgets` demo_str.cpp
But when I try to run it it immediately crashes. If I strip it down so that all it does is open a wxFrame with a wxMenuBar, wxPanel, and wxBoxSizer, it opens the window. But if I add 1 more line of code, putting a wxPLplotwindow in that panel, it crashes.

Here's the code. As you can see, I commented out many lines to pin down the problem. Line 130, instantiating the plotwindow, causes the segmentation fault. What am I missing?
Code:
/* $Id: demo_str.cpp,v 1.7 2005/12/14 08:49:28 smekal Exp $

   Copyright (C) 2005  Werner Smekal, Sjaak Verdoold
   Copyright (C) 2005  Germain Carrera Corraleche
   Copyright (C) 1999  Frank Huebner

   This file is part of PLplot.

   PLplot is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Library Public License as published
   by the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   PLplot is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with PLplot; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include <plplot/plplotP.h>
#include <plplot/wxPLplotwindow.h>


// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};


// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString& title);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
//    void OnZoomIn(wxCommandEvent& event);
//    void OnZoomOut(wxCommandEvent& event);
    
private:
	wxPLplotwindow* plotwindow;

  DECLARE_EVENT_TABLE()
};

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
enum { Minimal_Quit = wxID_EXIT, Minimal_About = wxID_ABOUT};
//        Minimal_ZoomIn = 10000, Minimal_ZoomOut };

// ----------------------------------------------------------------------------
// event tables and other macros for wxWidgets
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
	EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
	EVT_MENU(Minimal_About, MyFrame::OnAbout)
//	EVT_MENU(Minimal_ZoomIn, MyFrame::OnZoomIn)
//	EVT_MENU(Minimal_ZoomOut, MyFrame::OnZoomOut)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

// ============================================================================
// implementation
// ============================================================================

/*! This method is called right at the beginning and opens a frame for us.
 *
 * @author wxWidgets dev team
 * @date 2005.11.11
 */
bool MyApp::OnInit()
{
	MyFrame *frame = new MyFrame( _T("wxPLplot demo") );
	frame->Show( true );
	
	return true;
}


/*! Constructor of our custom frame, where the Menu is created and a
 *  a wxPLplotwindow is inserted into the frame. We plot some easy function
 *  just to show how it works. wxPLplotwindow takes care of all the setup
 *  for the use of PLplot library. We just need to get a pointer to the
 *  wxPLplotstream via the GetStream() method. This gives us access to the
 *  PLplot API.
 *
 * @author wxWidgets dev team, Werner Smekal
 * @date 2005.11.11
 */
MyFrame::MyFrame( const wxString& title )
       : wxFrame( NULL, wxID_ANY, title )
{
	// add menu
	wxMenu *fileMenu = new wxMenu;
	fileMenu->Append( Minimal_About, _T("&About...\tF1"), _T("Show about dialog") );
//	fileMenu->Append( Minimal_ZoomIn, _T("Zoom &in 10%\tCtrl++"), _T("Zoom in 10%") );
//	fileMenu->Append( Minimal_ZoomOut, _T("Zoom &out 10%\tCtrl+-"), _T("Zoom out 10%") );
	fileMenu->Append( Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program") );
	
	wxMenuBar *menuBar = new wxMenuBar();
	menuBar->Append( fileMenu, _T("&File") );
	SetMenuBar( menuBar );
	
	// add the wxPLplot
	wxPanel* panel = new wxPanel( this );
	wxBoxSizer* box = new wxBoxSizer( wxVERTICAL );
	plotwindow = new wxPLplotwindow( panel ); // ****** THIS LINE CAUSES SEG FAULT ******
//	box->Add( plotwindow, 1, wxALL | wxEXPAND, 0 );
  panel->SetSizer( box );
	SetSize( 640, 500 );
/*
	wxPLplotstream* stream = plotwindow->GetStream();

	stream->col0( 1 );
	stream->env( -2.0, 10.0, -0.4, 1.2, 0, 2 );
	stream->col0( 2 );

  stream->sdiplt( 0.0f, 0.0f, 1.0f, 1.0f );  
	
	stream->lab( "x-axis", "y-axis", "title" );
	
	// Draw the lines	
	int size=2048;	
  PLFLT* x = new PLFLT[size];
	PLFLT* y = new PLFLT[size];
	
	// Fill up the arrays.	
	for( int i=0; i<size; i++ ) {
	  x[i] = (i/20.48 - 19.0) / 6.0;
	  y[i] = 1.0;
	  if( x[i] != 0.0 )
	    y[i] = sin(2*x[i]) / (2*x[i]);
	}

	stream->col0( 3 );
	stream->wid( 2 );
	
	stream->line( size, x, y );
	stream->wid( 1 );
*/
//	plotwindow->Refresh();
}


/*! Close() method is called, if we get a quit event.
 *
 * @author wxWidgets dev team
 * @date 2005.11.11
 *
 * @param event : information about the event
 */
void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
{
	Close( true );
}


/*! Show information if Menu entry About was choosen.
 *
 * @author wxWidgets dev team, Werner Smekal
 * @date 2005.11.11
 *
 * @param event : information about the event
 */
void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
{
	wxMessageBox( _T("This is the About dialog of the wxPLplot sample.\n"), _T("About wxPLplot"),
                wxOK | wxICON_INFORMATION, this );
}


/*! This Zoom method doesn't work as expected :).
 *
 * @author Werner Smekal
 * @date 2005.11.25
 *
 * @param event : information about the event
 */
/*void MyFrame::OnZoomIn( wxCommandEvent& WXUNUSED(event) )
{
	wxPLplotstream* stream = plotwindow->GetStream();
  stream->sdiplz( 0.05f, 0.05f, 0.95f, 0.95f );    
	plotwindow->RenewPlot();
}
*/

/*! This Zoom method doesn't work as expected :).
 *
 * @author Werner Smekal
 * @date 2005.11.25
 *
 * @param event : information about the event
 */
/*void MyFrame::OnZoomOut( wxCommandEvent& WXUNUSED(event) )
{
	wxPLplotstream* stream = plotwindow->GetStream();
  stream->sdiplz( -0.05f, -0.05f, 1.05f, 1.05f );    
	plotwindow->RenewPlot();
}
*/

Last edited by r.stiltskin; 01-05-2010 at 04:35 PM. Reason: Solved.
 
Old 01-05-2010, 04:33 PM   #2
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Original Poster
Rep: Reputation: 31
Solved: apparently the PLplot wxWidgets driver (pkg plplot9-driver-wxwidgets) only works with wxWidgets version 2.6 (although it compiles with wxWidgets ver 2.8 without complaining).

I also found another demo in the PLplot 5.80 source download, the file is plplot-5.8.0/examples/c++/wxPLplotDemo.cpp.

Both of these demos run under wxWidgets-2.6.

One more thing: PLplot requires the ttf-freefont package.
 
  


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
Segmentation fault AndeAnderson Linux - Laptop and Netbook 2 03-21-2007 08:10 AM
Segmentation fault cmplet-noobie Programming 3 04-03-2006 02:52 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Segmentation fault compjinx Linux - Newbie 4 11-09-2003 04:51 PM
segmentation fault Linh Programming 6 11-03-2003 08:25 AM

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

All times are GMT -5. The time now is 12:21 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