Go to Post It is not brains but desire that matters. - Lancer Robotics [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-03-2016, 09:30
adamzg adamzg is offline
Mentor
AKA: Adam
FRC #3932 (Dirty Mechanics)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Boynton Beach, FL
Posts: 16
adamzg is an unknown quantity at this point
Re: WPILIB Camera Code Crashing JVM

Looking at the source for NIVision I think the .free() will work if used in a finally block. When we tried it the first time it didn't end up in a finally block and the image was being used as a member variable.

The NIVision class is calling C libraries that allocate memory outside the JVM so the correct steps we need are (pseudo code):
  • Image image;
  • try
  • allocate image - image = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0);
  • use image - CameraServer.getInstance().setImage(image);
  • finally
  • free image - image.free();

Will repost when we understand better.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-03-2016, 13:23
adamzg adamzg is offline
Mentor
AKA: Adam
FRC #3932 (Dirty Mechanics)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Boynton Beach, FL
Posts: 16
adamzg is an unknown quantity at this point
Re: WPILIB Camera Code Crashing JVM

Still crashing.

Here's the JVM version...

Code:
gsmin@roboRIO-3932-FRC:/usr/local/frc/bin# /usr/local/frc/JRE/bin/java -version -XX:+PrintCommandLineFlag
java version "1.8.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.8.0_06-b23, profile compact2, headless)
Java HotSpot(TM) Embedded Client VM (build 25.6-b23, mixed mode)
admin@roboRIO-3932-FRC:/usr/local/frc/bin# cd /usr/local/frc/JRE/bin    
admin@roboRIO-3932-FRC:/usr/local/frc/JRE/bin# ls
java         keytool      rmid         rmiregistry
admin@roboRIO-3932-FRC:/usr/local/frc/JRE/bin# cd
...stats from top at time of crash...

Code:
Mem: 176600K used, 75372K free, 0K shrd, 93K buff, 3067729088K cached
CPU:   9% usr  12% sys   0% nic  76% idle   0% io   0% irq   0% sirq
Load average: 2.22 2.15 2.30 4/290 8550
Reply With Quote
  #3   Spotlight this post!  
Unread 11-03-2016, 08:28
adamzg adamzg is offline
Mentor
AKA: Adam
FRC #3932 (Dirty Mechanics)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Boynton Beach, FL
Posts: 16
adamzg is an unknown quantity at this point
Re: WPILIB Camera Code Crashing JVM

Here is our latest and cleanest code with all the logic encapsulated in a single class. This still crashes the JVM...

Code:
public class CameraConfig {
	private AxisCamera camera;
	private String URL;
	
	public CameraConfig(String URL){
		this.URL = URL;
		this.camera = new AxisCamera(this.URL);
    	camera.writeExposurePriority(50);
	}
	
	public void sendImage() {
		Image image = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
		try {
			camera.getImage(image);
			CameraServer.getInstance().setImage(image);		
		} catch (Exception e) {
			System.err.println("Failed to get image from camera");
			System.err.println(e.getStackTrace());
		} finally {
			image.free();
		}
	}
	
	public boolean exists() {
    	boolean flag = false;
    	Image image = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
    	try {
    		camera.getImage(image);
    		flag = true;
    	}
    	catch (Exception e){
    		
    	}
    	finally {
    		image.free();
    	}
    	return flag;
	}
}
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi