packp3d - testing on winXP

If i unmark the ‘load font’ or ‘open file’ the packp3d file wont run anymore.(Runs fine as simple py file with load font and open file)

File structure:

game folder
-main.py
-smiley.egg
-tahoma.egg
-tahoma_1.rgb
-info.txt

import direct.directbase.DirectStart
from pandac.PandaModules import TextNode

#model
mod=loader.loadModel('smiley')
mod.setY(20)
mod.reparentTo(render)

print mod.findAllTextures()
#load font 
#tahoma = loader.loadFont('tahoma.egg')

#text
text=TextNode('textnode')
#text.setFont(tahoma)
textnode=aspect2d.attachNewNode(text)
textnode.setScale(0.1)

#load info
#file=open('info.txt', 'r')        
#info=file.read()
info='just some info'

#set info
text.setText(info)

run()

Next thing i found:

                newimg.setXelA(x-x1,y-y1,img.getXelA(x,y))

this line runs fine as py but crashes in p3d

Heres the function the line is in:

    def gettile(self,img,nr,tiles,size):
        tlist=[]
        lnr=len(nr)
        for i in range(lnr):
            gotit=False
            xp=nr[i]
            yp=0
            while not gotit:
                xp=xp-tiles
                yp+=1
                if xp<0:
                    gotit=True
                    xp=xp+tiles
                    yp-=1
                    
                elif xp<tiles-1:
                    gotit=True

            x1=size*xp
            y1=size*yp

            newimg=PNMImage(size,size)
            newimg.addAlpha()
            print 'set pos:',x-x1,y-y1
            print 'get pos:',x,y            
            for x in range(x1,x1+size):
                for y in range(y1,y1+size):
                    #
                    newimg.setXelA(x-x1,y-y1,img.getXelA(x,y))                
                    #
                    
            tlist.append(Texture())
            tlist[-1].load(newimg)

        return tlist
tahoma = loader.loadFont('tahoma.egg') 

Replace this with:

tahoma = loader.loadFont('tahoma') 

This is necessary because egg files are implicitly converted to bam files inside the p3d file, so you can’t use the .egg extension to name them. But if you omit the extension, the default is .egg when you run interactively, but .bam when you run in the p3d file.

file=open('info.txt', 'r')

Replace this with:

file=open(base.appRunner.multifileRoot + '/info.txt', 'r')

This is necessary because when you run the p3d file, your current directory is not the same place as the root directory of your p3d file. Any files that you load directly like this have to be referenced from their correct path. (I don’t think it’s a good idea to make the current directory be the same as the p3d file, because what would happen then if you tried to write to a file in the current directory?)

newimg.setXelA(x-x1,y-y1,img.getXelA(x,y)) 

I don’t see a problem with this, assuming that img has been properly loaded with an image of an appropriate size. Since you don’t do any bounds checking, though, it’s hard to be sure. And in the fully-optimized mode in which a p3d file runs, an exceeded bounds in the image will result in a hard crash, not a Python exception.

In what way does this line crash?

David

I tired to pinpoint it more preciely

        self.path='gfxdata/textures/'
        self.icons64=PNMImage()
        self.icons64.read(self.path+'icons64.png')
        
        self.tsize=64
        self.actimg=self.icons64
        
        self.test=self.gettile(self.actimg,[0],12,self.tsize)

    def gettile(self,img,nrs,tiles,size):        
        print img

        col=img.getXelA(0,0)#this line is enough to make it crash


        print col

And i found the solution:

        #self.icons64=PNMImage()
        #self.icons64.read(self.path+'icons64.png')
        self.icons64=loader.loadTexture(self.path+'icons64.png')
        self.pnim64=PNMImage()
        self.icons64.store(self.pnim64)

and it works

p3d does not like loading stuff directly as PNMImage

It’s the same problem: your current directory is not the root of the p3d file, so you just have to replace this:

self.path='gfxdata/textures/' 

with this:

self.path = base.appRunner.multifileRoot + '/gfxdata/textures/' 

It works when you use loader.loadTexture(), though, because the plugin adds the multifileRoot to the model-path, so loadTexture() can find it there. But PNMImage.read() doesn’t do any auto-searching.

David

Thank you drwr.

One more tiny issue:
.setBin(‘gui-popup’,50)
this does not affect nodes anymore

I use it to sort the order of gui grabbable objs

Edit:
by putting config.prc file in the same dir as main.py i cant still affect the window size and i cant really make sense of the sentence in the manual:
‘Any prc files within the toplevel of the application folder will be loaded automatically at runtime, as if $PANDA_PRC_DIR were set to your application folder name; you don’t need to load them explicitly in your Python code’

Ah, this is indeed a bug: we have not defined gui-popup in the plugin environment. I will add that config setting.

The default window size in the plugin environment is controlled by the environment itself. If you embed in a web page, it’s controlled by the web page. If you run via the panda3d executable, it’s passed in by the -s parameter to panda3d. The application is free to ignore this size, but you have to do it with a dynamically loaded config file, or by explicitly requesting a particular size when you call openWindow().

Some people like to write code to load a prc file with an explicit call to loadPrcFile(). You generally don’t need to do that in the plugin environment (unless you want to override something like the window settings).

David

Does it mean it will work in a new release of the runtime? or i still need to modify my code or some conf somehow?

Some more problems:
I red the manual but cant make sense of it.
panda3d.org/manual/index.php/P … g_settings

Currently if my p3d crashes it just closes and i cant see any log or console info.
'log_basename Specifies the log file within Panda3D/log to write to for this app ’
There are no log folder no start folder no prc folder in the Panda3D directory. Must i create them manually?
And i mean the default c:\programfiles…\Panda3D

Currently im creating the p3d file with this command line:
panda3d packp3d.p3d -o myopia.p3d -d Myopia -r ode -m client.py (takes approx 2 sec to build so this is nice)

what should i add so it would create the log and load custom prc settings?:
-c log_basename=mylog -c prc_name=myprc
where mylog and myprc are manually created folders under Panda3D/log folder?

File pathing structure problems:

I would like the game structure to be:

Game name(folder)
 game.p3d(file)
 data(folder)
  lang(folder)
   some files
  char(folder)
   some files
  temp(folder)
   some files

I would like the user to be able to create content and upload it so i need the separate folders where users can put their language files(txt format) flag images(png) and custom model and textures.

But the p3d file does not create these folders anymore? or does it create them inside it self?
Cos it saves the changes and restarting the application loads correct data(at least for the character).
i could add a browse method yet i dont see the need for it, as what can be uploaded has very strict rules anyways.

God does not punish the stupid, at least not that often
Thank you.

It will just work in the next release. But in the meantime, you can work around it yourself by adding the line:

cull-bin gui-popup 60 unsorted

to your app’s prc file (that is, a .prc file in the app’s root directory).

Ah, my apologies. You are looking in the wrong place for the log info. The Panda3D directory it is referring to is under %LocalAppData% directory, which is c:\Documents and Settings<your name>\Local Settings\Application Data\Panda3D on Windows XP, or c:\Users<your name>\AppData\Local on Vista or Win7. In this folder you will find all of your log output, and also the directory in which you can install your personal prc files. (Note that these prc files are different from the application’s built-in prc file. This is where the end-user will install personal configuration options, not where the application will configure itself. The application configures its own defaults by putting a prc file in the root of its own p3d file.)

You will also find local files created by your app in the Panda3D/start folder. So this is where your app might store its local data store for the user to store content.

David

Thank you David, all good but the .prc and bin

I run my app as py file, all good.

I copy the config.prc to Myapp folder, same folder as my main.py(client.py in my case is). I add the line to config.prc: cull-bin gui-popup 60 unsorted

I build the p3d with this line:
panda3d packp3d.p3d -o Myopia.p3d -d Myopia -r ode -m client.py

I start the p3d file, gui obj dont pop up.

Actually no changes in the config.prc(the one in the same folder as main.py)affect the p3d. I cant even make the p3d file run in full screen.

Am i putting the config.prc to the wron dir? or is there something else im missing?

Thank you.

Ah, my apologies. Certain config variable settings may only be defined at application startup; if they are read later, they have no effect. As it happens, cull-bin is one of those variables. Since the p3d file is read after application startup, it doesn’t help to define cull-bin in the application’s prc file; you have to define it at runtime instead with code like this:

cbMgr = CullBinManager.getGlobalPtr()
cbMgr.addBin('gui-popup', cbMgr.BTUnsorted, 60)

Similarly, you cannot set the application to fullscreen (or set its size or placement) in the app prc file, because the window mode and size is specified by the plugin code.

But most other config variables do have effect there. For instance, you can put:

show-frame-rate-meter 1

in your app’s prc file, and it will enable the fps meter in the corner at startup. To prove that you have loaded your app’s prc file, you can print:

print cpMgr

in your code; it will list the prc files it has read.

David

Does that really not even work with the new runtime fullscreen toggling code?

Oh, sure–you can change to fullscreen with python code. You just can’t put “fullscreen 1” in your Config.prc and expect it to be respected there.

David

Thank you David, got the prc and bin working.

Next problem:
If i run panda3d.exe on one of my machines it shows ‘Usage: lots of inf
Optionas:lots of inf’
in the console.

If i try to run panda3d.exe on my other machine it says ‘The system cannot execute the specified program.’
And the there is no panda3d folder in document and setting/user/loacal settings/app data so no logs or anything.

Both machines have winXp and panda runtime ver 9.10.

Hmm, are you sure that panda3d.exe is on your path? What happens if you double-click on a p3d file?

David

yes its on the path as it recognizes them as panda p3d files and displays them with correct icon.

if i double click:
Error executing program!

if i drag drop into browser:
This applications has failed to start because the application configuration is incorrect.Reinstalling the application may fix this problem.

I have tryed reinstalling but nothing changed

So it seems to me it has something to do with this specific computer.(i hope im wrong)

Can you try installing the .NET Framework 3.5?

Thank you that did the magic.

New issue:

    def togglefscr(self):
        if base.win.isFullscreen():
            #go windowed
            base.win.requestProperties(self.wp)
            
        else:
            #save windowed props
            self.wp=WindowProperties(base.win.getProperties())
            
            #go fullscreen
            props.setFullscreen(True)
            w=base.pipe.getDisplayWidth()
            h=base.pipe.getDisplayHeight()            
            props.setSize(w,h)
            base.win.requestProperties(props)

It switches to fullscreen if run as py file, but as p3d it keeps the decorations, and it seems it just does wp.setSize(w,h),so not really a fullscreen.

And it does not change back to correct window size.

Am i using it wrong?

So far i have been using code from this thread:
discourse.panda3d.org/viewtopic … 5b33fc531b

And that worked fine, both as py and p3d(with p3d it does sometimes silent closes)