Assertion failed using GeoMipTerrain

Note: Edit this from a double post.

Hi, I am having a pretty strange problem with GeoMipTerrain.
I did a smaller program with no threads, pretty simple, it has no window and states no pandaFramework.
It only loads a height field and gets some the elevation of some random x,y.

From this example I created a class, the object receives a filename and a scale.
The object loads and scales the map in Z.
There is a public method that, given a x and a y position, returns the z (it multiplies by the scale to get it right).

The program that uses this object is multi-thread.
When the program runs it prints this message everytime:

Assertion failed: _num_channels >= 1 && _num_channels <= 4 at line 77 of built/include/pnmImageHeader.I
Assertion failed: x >= 0 && x < _x_size && y >= 0 && y < _y_size at line 301 of built/include/pnmImage.I
Assertion failed: x >= 0 && x < _x_size && y >= 0 && y < _y_size at line 301 of built/include/pnmImage.I
Assertion failed: x >= 0 && x < _x_size && y >= 0 && y < _y_size at line 301 of built/include/pnmImage.I

I tried using and PNMImage, but the file wouldn’t even load.
Using both a string and a filepath gives me this warning everytime someone calls the get_elevation.

Since the image is 512x512 it also says:

:grutil(warning): Rescaling heightfield image /home/fernando/Documents/sandbox/collisionTest/small_heightmap.png from 512x512 to 513x513 pixels.

Any tips?

Edit 2:

Now I am getting a seg fault…

==10502== Use of uninitialised value of size 8
==10502==    at 0x59BAE8B: GeoMipTerrain::get_elevation(double, double) (in /usr/lib/panda3d/libpanda.so.1.7)
==10502==    by 0x405A87: CollisionHandler::calculateZ(double, double) (collision.cpp:23)
==10502==    by 0x40B964: Monster::Monster(unsigned long) (monster.cpp:15)
==10502==    by 0x409E50: main (main.cpp:67)
==10502==  Uninitialised value was created by a heap allocation
==10502==    at 0x4C27CC1: operator new(unsigned long) (vg_replace_malloc.c:261)
==10502==    by 0x405AED: collisionHandlerInit() (collision.cpp:28)
==10502==    by 0x409D9B: main (main.cpp:38)
==10502== 
==10502== Invalid read of size 4
==10502==    at 0x59BAE8B: GeoMipTerrain::get_elevation(double, double) (in /usr/lib/panda3d/libpanda.so.1.7)
==10502==    by 0x405A87: CollisionHandler::calculateZ(double, double) (collision.cpp:23)
==10502==    by 0x40B964: Monster::Monster(unsigned long) (monster.cpp:15)
==10502==    by 0x409E50: main (main.cpp:67)
==10502==  Address 0xd8 is not stack'd, malloc'd or (recently) free'd
==10502== 
==10502== 
==10502== Process terminating with default action of signal 11 (SIGSEGV)
==10502==  Access not within mapped region at address 0xD8
==10502==    at 0x59BAE8B: GeoMipTerrain::get_elevation(double, double) (in /usr/lib/panda3d/libpanda.so.1.7)
==10502==    by 0x405A87: CollisionHandler::calculateZ(double, double) (collision.cpp:23)
==10502==    by 0x40B964: Monster::Monster(unsigned long) (monster.cpp:15)
==10502==    by 0x409E50: main (main.cpp:67)

Thanks in advance.

I also got the grutil error when trying to load a .png or .jpeg image as a height map. Nare you developing on windows XP

That’s not supposed to happen. Can you file a bug report and attach a small piece of code and the heighfield that reproduce this error?

For the record, you should be passing a 513x513 image, rather than 512x512.

Also, I’m nervous about this:

Are you careful to use only Panda threading constructs throughout, and not use the system threading library provided by Python? This is a common mistake among Panda developers who wish to use threading.

David

For what it’s worth, I don’t think I ever made GeoMipTerrain thread-safe, so make sure to lock your calls or only make calls to it from within the main thread.