[vtkusers] extending vtk classes in java, seg faults in superclass methods

David Marshburn marshbur at cs.unc.edu
Fri May 13 14:43:26 EDT 2005


in particular, i'm trying to extend the vtkImageSource class.  i'm using 
some other, external classes to load image stacks of various types, and 
i'd like to get these image data into vtk for visualization.  for this, i 
made an adapter class that extends vtkImageSource; however, whenever i try 
to call any vtkImageSource methods inside the contructor, i get an access 
violation.  below is an example of some code that crashes and the 
resulting error report.

this initially happened with the SetOutput method, but it also happens 
with things as simple as GetClassName.

in the case of SetOutput, the debugger identifies a line in
vtkSource::SetNthOutput, and the line is   
	if (idx >= this->NumberOfOutputs)
this makes me wonder if everything is being correctly initialized.

questions:  is it just not possible to subclass vtk classes with vtk in 
its java-wrapped form?  i'd be surprised (we do so elsewhere).  is there 
something else i need to be doing (beyond what's done in the superclass 
contructor) to initialize vtk superclasses from java?  

all the vtk native libraries have been loaded by the time this code 
executes.  also, this code is called from the swing thread, through which 
all other vtk access is synchronized (the seg fault also happens 100% 
repeatably on first invocation, which is not as characteristic for a race 
condition).

this is with vtk 4.4 and java 1.4.1.

i appreciate any thoughts or suggestions.

-david

-------------------------------------------

public class Image2vtk extends vtkImageSource
{
	protected vtkImageData imageData_vtk = new vtkImageData( );

	public Image2vtk( ImagePlus ip )
	{
		super();  // explicit, just to make sure
	
		... // set up and fill in imageData_vtk

		this.SetOutput( imageData_vtk );  // seg fault here
		this.GetClassName();  // also causes a seg fault
	}
}


An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0xB85B08B
Function=vtkSource::SetNthOutput+0x12B
Library=C:\Program Files\vtk44\bin\vtkCommon.dll
Source file = D:\nsrc\VTK\Common\vtkSource.cxx : 626

Current Java thread:
	at vtk.vtkImageSource.SetOutput_2(Native Method)
	at vtk.vtkImageSource.SetOutput(vtkImageSource.java:20)
	at ImageJ2vtk.<init>(ImageJ2vtk.java:88)
	at DataLoader.loadFiles(DataLoader.java:389)
	at DataLoader$3.actionPerformed(DataLoader.java:282)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
	<snip lots more stack trace>



More information about the vtkusers mailing list