Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jo
Jan 24, 2005

:allears:
Soiled Meat
I've heard performance takes a serious hit when it comes to using immediate mode (a la glBegin() and glEnd()) versus using display lists.

If I'm rendering geometry that moves, changes textures, and has dynamic lighting, can I still use display lists?

Adbot
ADBOT LOVES YOU

Jo
Jan 24, 2005

:allears:
Soiled Meat
Thanks for the responses.

kewlpc posted:

Yeah, display lists are faster.
The fastest way, however, would be vertex arrays or VBOs.

I did not know this. I thought display lists were faster because they were 'compiled' and stored.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm looking for an image library for C++ that meets the following criteria:

1) Read/Write .jpg, .gif, .png
2) Simple, consistent data types for images with direct access to pixel data, a la [x][y][rgb].
3) Can be easily linked into an executable or have minimal external dependencies.
4) Tiny

I've tried:
cImg -- Too big. Does everything I need and too much more.
opencv -- Again, too big. Also really hard to get pixel access. Kinda' convoluted interface.

Any recommendations?

Jo
Jan 24, 2005

:allears:
Soiled Meat

litghost posted:

Can't you just use libjpeg and libpng?

I forgot about that. :saddowns: Probably.


Smackbilly posted:

Take a look at Magick++.

Not sure if it qualifies as tiny, but it does meet your other criteria.

This looks good. I'll try it.

Jo
Jan 24, 2005

:allears:
Soiled Meat
Why is mmap always returning -1:

code:
int filePtr = open( sharedFileName, (O_CREAT|O_RDWR), (S_IRUSR|S_IWUSR|S_IRGRP) ); // Open file
_shared = (RPCShared *)mmap( NULL, sizeof(RPCShared)*maxAvailableThreads, (PROT_READ|PROT_WRITE), MAP_SHARED, filePtr, 0 );
if( (int)_shared == -1 ) {
	fprintf( stderr, "ERROR: Error mapping shared memory.  mmap returned -1 :(\n" );
	exit(-1);
}
I've tried dinking around with the options, and it doesn't matter what I do with maxAvailableThreads or RPCShared. Should I be doing something special with addr?

EDIT: Added MODE data. Still no go.

Jo fucked around with this message at 08:41 on Nov 21, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat

ShoulderDaemon posted:

Perhaps you could print out the actual error? errno exists for a reason, you know.

Ehr, yes. Right. It's errno 9.
Bad file descriptor.

EDIT: It's late, I'm probably making a stupid error opening the file or something.
Thank you for your response at this ungodly hour, ShoulderDaemon.

:doh: server1.rpc has permissions hosed up.

Jo fucked around with this message at 09:09 on Nov 21, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat

Vanadium posted:

Ever tried out strace?

Never heard of it before. Looks really neat, but it's not installed on the dev server and I don't have administrative privileges.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm getting a sigabrt on a delete. I know it's a memory management problem, but I don't see why...

code:
Image * plessyFilter( Image * img, float k = 0.04 ) {
	Image * plessy = new Image( img->getWidth(), img->getHeight() );
	Image * gaussian = runGaussian3x3( img );
	
	// snip!

	delete gaussian;
	return plessy;
}
... the delete fails on the gaussian image. If I use new inside the runGaussian function, it (the blurred image) should NOT be deleted when I return from runGaussian. Why would the data allocated with new disappear on a return?

Jo
Jan 24, 2005

:allears:
Soiled Meat

ultra-inquisitor posted:

Is runGaussian3x3 in a different DLL, or are you using new[] to allocate the memory?

Right now it's just new[].

Avenging Dentist posted:

Why wouldn't you just use a smart pointer there?

v:shobon:v

Guess I'll have to, but I still don't see why it doesn't work. Perhaps I have a horrid and fundamental misconception about pointers.

code:
int * thingFunc( void ) {
  int * thing = new int[100];
  return thing;
}
The memory set aside using new should not be deleted until I do so manually, yes?

EDIT: I got rid of 'delete gaussian' at the end of the function and the program works. I'm not sure why, exactly, and I'm probably leaking memory; it terminates shortly after returning from the function, so I'm not terribly worried.

EDIT 2: Only for you, Otto Skorzeny. ;-*

A typo in the gaussian function made this:

Jo fucked around with this message at 18:40 on Dec 6, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat

Otto Skorzeny posted:

If you have valgrind you can check whether you're leaking memory pretty easily (as long as your program doesn't have a long run time as-is).


e: hey put that image back up it was :coal:

Yup, it would seem a leak is present.
==17230== LEAK SUMMARY:
==17230== definitely lost: 2,718,128 bytes in 16 blocks.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Vanadium posted:

If you allocate memory with new[], you have to deallocate it with delete[].

Yes, I'm readily aware, but when I call delete[], I get a sigabrt.

EDIT:
Aaah, I see what you're saying. No, it's just a simple Image * gaussian = new Image( blahblah ). The delete still delete, in this case, no?

Jo fucked around with this message at 19:36 on Dec 6, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat

schnarf posted:

What does the destructor for Image do? Is it possible that the constructor does something with the pointer to img and then something funky happens in the destructor?

Image is largely a wrapper for another image library with import/export functionality.

code:
~Image() {
	delete[] redData;
	delete[] greenData;
	delete[] blueData;
	width = 0;
	height = 0;
}
A thousand thank yous to those who responded. I hosed around (rewrote) the gaussian function and things are up and working now. There's still a memory leak, but I don't expect that to be too hard to trace. Again, many many thanks.

Jo
Jan 24, 2005

:allears:
Soiled Meat
Somewhere in my loving huge (tm) operating systems project, a there is a memblock->next = memblock. I can't do a simple search through the text, as the assignment happens when the program is running. (Lots of pointer dumbfuckery and the like.) What tools can I use other than gdb and ddd exist to help with this screaming headache?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Avenging Dentist posted:

All assignments happen when a program is running. :confused: (Excluding const PODs, etc).

Ehr, yes. That was poorly phrased. The assignment is the end result of a series of operations when I run the application. I.e. a->next = b; b->next = c; c->next = d; d->next = a; Remove c, b->next = d; Remove b, a->next = d; Remove d, a->next = a;

The bug doesn't arise in small scale tests. It's large-scale 5 minute long stress tests that make it pop up. :argh:

In a perfect world, I'd like to be able to set up a monitor that detects when the assignment obj->next = obj is made. Is this possible?

TheSleeper posted:

How many places in your code are you actually assigning to memblock->next? I mean would it be reasonable to just assert(&memblock != &memblockToBeNext) before the assignment and backtrack from there to find the bug?

Only a few, and there are a number of checks in place to catch that sort of thing; making it all the more maddening when it shows up.

Jo fucked around with this message at 05:42 on Dec 14, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm having a strange problem with std::deques.

code:
void legalizeTriangle( Triangle * t, deque <Triangle*> triangulation ) { /* blah */ }

list <Triangle*> triangulate( list <Point*> points ) {
	/* blahblahblah */
	legalizeTriangle( trianglesToCheck.at(i), triangles );
}
Which is freaking out. Running gdb,

Before legalizeTriangle, triangles.size() is 3. I step into legalizeTriangle and the size of triangles is 67896278964243840598345

code:
220                     Point * points = triangulation.at(i)->getPoints();
(gdb) print triangulation.size()
$7 = 1161059713442302
(gdb) up
#1  0x0000000000445bf1 in triangulate (points=
            {<std::_List_base<Point*, std::allocator<Point*> >> = {_M_impl = {<std::allocator<std::_List_node<Point*> >> = {<__gnu_cxx::new_allocator<std::_List_node<Point*> >> = {<No data fields>}, <No data fields>}, _M_node = {_M_next = 0x7fff4e88e9e0, _M_prev = 0xc2c450}}}, <No data fields>}) at delaunay.h:301
301                             legalizeTriangle( trianglesToCheck.at(i), triangles );
(gdb) print trianglesToCheck.size()
$8 = 3
(gdb) print triangles.size()
$9 = 2
I'm not throwing any pointers around. Why would this happen?

EDIT: For clarity, the size changes AS SOON as I step into the function. It's as if passing the stl container changes the values inside.

Jo fucked around with this message at 20:55 on Jan 1, 2009

Jo
Jan 24, 2005

:allears:
Soiled Meat

shrughes posted:

What the gently caress are you talking about? Learn how to communicate properly.

Edit: Your compiler's broken.

Edit: Why don't you isolate the problem in some demonstratory program, so that people can actually tell you what's wrong, rather than saying "Hey, you're right, that looks funny."?

Noted. I thought the GDB excerpt was self explanatory. I'll try to be more clear.

Also, working on an isolated test case.

Jo
Jan 24, 2005

:allears:
Soiled Meat

beuges posted:

Don't you want to make LegalizeTriangle take a const reference rather than make a copy?

code:
void legalizeTriangle( Triangle * t, const deque <Triangle*>& triangulation ) { /* blah */ }

Goddamnit. :doh:

Works now. Thank you.

Jo
Jan 24, 2005

:allears:
Soiled Meat

whoknew posted:

A lot of the time in C++ you can get around a problem by changing the way you wrote the code slightly, but if you don't know why that change fixed it, you shouldn't assume that it's actually fixed. You definitely clobbered something, somewhere.

Perhaps there is a latent problem. I'm really not sure _why_ the problem was happening in the first place. As some stated, this should not have happened.

The full source code for the triangulation functions is here.

http://pastebin.com/m5ff26445

The tests for the triangle functions, line functions, and points functions have passed. The tests for the swap edge have passed. Tests for find common edge have passed. (Though common edge tests were not terribly extensive.)

I hesitate to post the full code because I'd hate to force anyone to shuffle through it all. :xd:

EDIT: There are a few nasty code-bits. The lack of breaks in the swapEdge function is vestigial -- debugging efforts that haven't been cleaned up completely.

Jo
Jan 24, 2005

:allears:
Soiled Meat

rjmccall posted:

This would be somewhat less painful to debug if you were using references more and pointers less. Also, sometimes you delete[] the return value from getPoints(), and sometimes you don't.

Returning a std::list (as opposed to a pointer to a malloc'ed one, or some other way of passing the information back) is a bad idea, but it's probably not a memory bug.

Anyway, that's what I see in a quick scan.

I'll keep these in mind if I rewrite everything. (Likely) Thank you very much for your time.

ani47 posted:

The only problem I think I can see (apart from memory leaks and overuse of new/delete) is you don't clear your trianglesToCheck deque after to add them to the other triangles deque here:

code:
for( int i=0; i < trianglesToCheck.size(); i++ ) {
       legalizeTriangle( trianglesToCheck.at(i), &triangles );
       triangles.push_back( trianglesToCheck.at(i) );
}

YES! Excellent! Thank you so much for noticing that. Good eye.

Jo fucked around with this message at 19:03 on Jan 2, 2009

Jo
Jan 24, 2005

:allears:
Soiled Meat
Complete reedit:

It's amazing what wonders can be done when visualizing the tiny pieces.

code:
Enter triangle coordinates [i.e. x y x y x y]: 10 10 10 20 20 10
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
..........###########...................
..........#tttttttt#....................
..........#ttttttt#.....................
..........#tttttt#C.....................
..........#ttttt#CC.....................
..........#tttt#CCCC....................
..........#ttt#CCCC.....................
..........#tt#CCCCC.....................
..........#t#CCCCC......................
..........##...C........................
..........#.............................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
:what:

code:
		circumcircleRadiusSquared = getDistanceSquared( circumcircleX, circumcircleY, points[0].x, points[0].y );
		circumcircleRadiusSquared = getDistanceSquared( circumcircleX, circumcircleY, points[1].x, points[1].y );
		circumcircleRadiusSquared = getDistanceSquared( circumcircleX, circumcircleY, points[2].x, points[2].y );
		circumcircleRadiusSquared = circumcircleRadiusSquared/3;
code:
		circumcircleRadiusSquared += getDistanceSquared( circumcircleX, circumcircleY, points[0].x, points[0].y );
		circumcircleRadiusSquared += getDistanceSquared( circumcircleX, circumcircleY, points[1].x, points[1].y );
		circumcircleRadiusSquared += getDistanceSquared( circumcircleX, circumcircleY, points[2].x, points[2].y );
		circumcircleRadiusSquared = circumcircleRadiusSquared/3;
:downsbravo:


code:
jo@Gauss:~/source/HotSauce$ ./testTriangle
Enter triangle coordinates [i.e. x y x y x y]: 10 10 10 20 20 10
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
...............C........................
............CCCCCCC.....................
..........###########...................
..........#tttttttt#C...................
.........C#ttttttt#CCC..................
.........C#tttttt#CCCC..................
.........C#ttttt#CCCCC..................
........CC#tttt#CCCCCCC.................
.........C#ttt#CCCCCCC..................
.........C#tt#CCCCCCCC..................
.........C#t#CCCCCCCCC..................
..........##CCCCCCCCC...................
..........#CCCCCCCCC....................
............CCCCCCC.....................
...............C........................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................

Jo fucked around with this message at 01:01 on Jan 10, 2009

Jo
Jan 24, 2005

:allears:
Soiled Meat

PT6A posted:

You shouldn't seed the random number generator every turn, only once at the beginning of your program.

:pseudo: Seeding more makes it more random! :downs:

Jo
Jan 24, 2005

:allears:
Soiled Meat
Is there a way to cross compile for Windows on Linux without MinGW?

Jo
Jan 24, 2005

:allears:
Soiled Meat
EDIT: gently caress this.

Jo fucked around with this message at 03:51 on Jan 18, 2009

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm having a hell of a time linking CGAL. One of the google links actually points here to the forums, but I don't see an actual library name. (I.E. -lcgal) Do I really need to use cmake, or is there a linker command like -lcgal that will work?

EDIT: -lcgal != -lCGAL :downs:

Jo fucked around with this message at 23:25 on Jan 18, 2009

Jo
Jan 24, 2005

:allears:
Soiled Meat

Gvaz posted:

Idk what mv is but I did that and nothing changed on ./chall3.c or .h (idk which we're supposed to save them as, someone told me not to save as .h)

mv is the *nix command for 'move'. It has the same functionality as rename. Your main function should be in a .c file, not in a header (.h) file.

EDIT: Haha! Caught you before the ninja edit.

Jo
Jan 24, 2005

:allears:
Soiled Meat
It's late and I'm getting retarded. Is there an obvious flaw with this function?

code:
Image * convolutionMatrix_5x5_kernel( Image * img, double matrix[] ) {
	Image * distImg = new Image( img->getWidth(), img->getHeight() );
	
	for( char v=0; v < 3; v++ ) {
		for( int y=2; y < img->getHeight()-2; y++ ) {
			for( int x=2; x < img->getWidth()-2; x++ ) {
				int value = ( 
					(((double)img->getPixel(x-2,y-2,v)* matrix[ 0]) + ((double)img->getPixel(x-1,y-2,v)* matrix[ 1]) + ((double)img->getPixel(x+0,y-2,v)* matrix[ 2]) + ((double)img->getPixel(x+1,y-2,v)* matrix[ 3]) + ((double)img->getPixel(x+2,y-2,v)* matrix[ 4])) +
					(((double)img->getPixel(x-2,y-1,v)* matrix[ 5]) + ((double)img->getPixel(x-1,y-1,v)* matrix[ 6]) + ((double)img->getPixel(x+0,y-1,v)* matrix[ 7]) + ((double)img->getPixel(x+1,y-1,v)* matrix[ 8]) + ((double)img->getPixel(x+2,y-1,v)* matrix[ 9])) +
					(((double)img->getPixel(x-2,y+0,v)* matrix[10]) + ((double)img->getPixel(x-1,y+0,v)* matrix[11]) + ((double)img->getPixel(x+0,y-0,v)* matrix[12]) + ((double)img->getPixel(x+1,y-0,v)* matrix[13]) + ((double)img->getPixel(x+2,y+0,v)* matrix[14])) +
					(((double)img->getPixel(x-2,y+1,v)* matrix[15]) + ((double)img->getPixel(x-1,y+1,v)* matrix[16]) + ((double)img->getPixel(x+0,y+1,v)* matrix[17]) + ((double)img->getPixel(x+1,y+1,v)* matrix[18]) + ((double)img->getPixel(x+2,y+1,v)* matrix[19])) +
					(((double)img->getPixel(x-2,y+2,v)* matrix[20]) + ((double)img->getPixel(x-1,y+2,v)* matrix[21]) + ((double)img->getPixel(x+0,y+2,v)* matrix[22]) + ((double)img->getPixel(x+1,y+2,v)* matrix[23]) + ((double)img->getPixel(x+2,y+2,v)* matrix[24])) );
				distImg->setPixel(x,y,v,value);
			}
		}
	}

	return distImg;
}

Jo
Jan 24, 2005

:allears:
Soiled Meat

Ugg boots posted:

Are you sure those values are going to fit into an int?

:doh: :saddowns:

Jo
Jan 24, 2005

:allears:
Soiled Meat

Randall posted:

I just bought Accelerated C++ by Koenig/Moo today. I'm not even on chapter 2 and am already lost.

I consider myself fairly knowledgeable in computer tech but I have no experience in any programming language whatsoever. I decided this would be something I'd like to learn and didn't expect it to be easy but, jeez, so much of the jargon used in the book goes over my fragile little mind. :psyduck:

It's been a long while since I started programming, so take this with a giant spoon of salt. The best way to become proficient in a programming language is to use it. Build tiny applications -- simple things like

Hello World.
Hello (name).
A program that takes a text file and adds line numbers.
A simple calculator.
etc

This will teach you something beyond, "Okay public static void main here," and into the realm of understanding WHY things are being done the way they are.

Adbot
ADBOT LOVES YOU

Jo
Jan 24, 2005

:allears:
Soiled Meat
Got it working! Yaaay!

Jo fucked around with this message at 22:36 on Jul 31, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply