I am setting window-type to none and am later calling base.openDefaultWindow(startDirect=False, props=WindowProperties.getDefault(), keepCamera=True) to open a window. I get:
Assertion failed: (rnode->_memory_usage[memory_class] >= 0), function dec_memory_usage, file typeHandle.cxx, line 85.
Any ideas on where to start digging?
Thanks as always
Looks like this is caused by loading a model before opening the window. It seems like loading a model shouldn’t be tied to a particular display (rather, only drawing a frame once we start the main loop should require a window), is this not true?
That is true, generally.
Panda can make some optimizations about to your model if you wait until after you have opened a window to load it. For instance, OpenGL and DirectX use incompatible representations for vertex color. if you use an OpenGL graphics window, then Panda will know it should reformat your model to use OpenGL’s color representation, but if you use a DirectX window, Panda will refort it to use DirectX’s representation.
Also, different graphics cards have different limits on the number of vertices that can be sent at once. Panda will make an attempt to optimize your scene to the graphics card’s advertised capabilities, if you have already opened the window.
But all these are just minor optimizations. It should work just fine if you load the model before you have opened the window. In fact, I just tested it myself, and it does indeed work fine for me.
The assertion failure you reference is curious. It indicates a mismatch between malloc and free calls: a memory block was freed that was never allocated, at least not by Panda. This might conceivably have something to do with the timing of when you started Panda (though it’s hard to imagine the details), but I don’t know how it would have anything to do with opening a window or not.
Can you tell us more about the platform you are running on and the version of Panda you are using? Is this 100% repeatable, and are you sure it is related to loading a model before opening a window?
I am running Panda 1.4.1 on Mac OS X 10.5 (Leopard). It is indeed repeatable. I moved my openDefaultWindow(…) call to the start of a test script and things worked, then I started to move it down line by line, and the error came back after moving it after the block that loads the first model.
Curious question… let’s say things were working, how much would I be losing by loading the window later? Do the optimizations improve frame rate, appearance, a combination, or something else?
It seems to be unhappy with loading the display library in this situation. In panda3d/dtool/src/dtoolutil/load_dso.cxx the line “void * answer = dlopen(fname.c_str(),RTLD_NOW| RTLD_LOCAL)” fails when trying to load “libpandagl.dylib”.
My first guess would be that the order in which libptloader.dylib and libpandagl.dylib are loaded are causing problems. It seems to want ptloader first.
Edit: I meant, it seems to want pandagl first.
OK, the Mac build has always had weird ordering issues with loading dynamic libraries. I’ll see if I can repro the problem on the Mac.
It is a small performance/memory optimization. If Panda is not able to pre-optimize the model at load time, it will have to do so at render time instead, but then it will cache the result. So, failing to pre-optimize the model will have very little impact on your actual performance (since, once cached, it is still optimal), but your internal cache will be a bit larger.
You can also pre-optimize your model after loading it with model.premungeScene(). Mostly, this is such a small optimization that it’s not even worth spending the time to think about it, though, unless you are really in the weeds for every last microsecond of performance and byte of RAM.