Thread: Impossible call 'patch' inside onkeydown handler?
Status: Alpha
Brought to you by:
cwalther
From: Andrea V. <and...@gm...> - 2008-01-28 14:01:11
|
Hello! I got a strange behavior with build 179 and this simple code: -------------------------------------------------------------- cubic { "skyFront.jpg", --front "skyRight.jpg", --right "skyBack.jpg", --back "skyLeft.jpg", --left "skyTop.jpg", --top "skyBottom.jpg" --bottom } onkeydown ( function(key) p_ref=patch{nx=1,ny=1,nz=0,nw=1,nh=1,angley=90,image="left.png"} return false end ) -------------------------------------------------------------- When you press a key, you will get the message: Error running local keydown handler: 1/node.lua:13: attempt to call global 'patch' (a nil value) if I substitute patch with pipmak_internal.patch, it seems to work fine, for this simple example, but using a more complex code, Pipmak crash in that point... With the debug I have seen that the error occur in images.c ---------------------------------------------------------------------- void releaseImageFromGL(Image *img) { img->texrefcount--; /// <--error occur in this point if (img->texrefcount <= 0) { glDeleteTextures(1, &(img->textureID)); img->textureID = 0; } ---------------------------------------------------------------------- What do you thinking about? Is it a problem of my build, or really I cannot define a new patch inside a keydown handler? Bye. Andrea |
From: Christian W. <cwa...@gm...> - 2008-01-29 20:59:21
|
Andrea Viarengo wrote: > onkeydown ( > function(key) > p_ref=patch{nx=1,ny=1,nz=0,nw=1,nh=1,angley=90,image="left.png"} > return false > end > ) > -------------------------------------------------------------- > > When you press a key, you will get the message: > > Error running local keydown handler: > 1/node.lua:13: attempt to call global 'patch' (a nil value) This is by design. "patch" is only available at node loading time, not as a run-time function. You should not think of it as a function (even though it technically is one), but as part of a declarative node description syntax. > if I substitute patch with pipmak_internal.patch, it seems to work fine, > for this simple example, > but using a more complex code, Pipmak crash in that point... You're not supposed to use pipmak_internal. It's called internal for a reason... We should probably make sure that you can't crash Pipmak even if you do, but that looks quite tedious... :/ > Is it a problem of my build, or really I cannot define a new patch inside > a keydown handler? You can't create patches at run time. What would you need that for? Would it be very inconvenient to have to reload the node for it? -Christian |
From: Andrea V. <and...@gm...> - 2008-01-31 10:25:07
|
Christian Walther <cwalther <at> gmx.ch> writes: > You can't create patches at run time. What would you need that for? > Would it be very inconvenient to have to reload the node for it? Ok, I understand you, I should find a workaround to this. Well, I'm working on a lua library fot drawing simple 3d object, as explain you before, the big problem is put the patches in the correct geometrical order, So, for the moment I have operate in this manner: I calculate all the parameters to drawing patches of my 3d object (nx,ny,...angley...image...) and put inside a table. During this phase I eliminate backfaces to reduce total number of patches. I reorder the table of the patches from farest to nearest I cycle along the table and draw the patch, To do this, I use another table to store patch id, I reuse patches stored in this table that are always ordered from back to front. If I found a patch in this table, I use it, otherwise I create a new one and I append it to the table for future use. Because the backface removal, the number of patches that I see can vary depending on the angle of view. So if I want to schedulate the rotation of my object, it's possible which, for some angle of view, I need extra patches... Now I have to predetermine the maximum number of patches and allocate all patches before runtime. If I eliminate backfaces removal, the problem never occur, because the number of the faces is always the same. I have tryed (just for test) to enable depth buffer on SDL (before calling SDL_SetVideoMode( width, height, bpp, flags ) using: SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); but it's not sufficient, because the behaviour isn't changed..... Bye Andrea |
From: Christian W. <cwa...@gm...> - 2008-01-31 12:00:08
|
Andrea Viaengo wrote: > Christian Walther <cwalther <at> gmx.ch> writes: > >> You can't create patches at run time. What would you need that for? >> Would it be very inconvenient to have to reload the node for it? > > Ok, I understand you, I should find a workaround to this. > > Well, I'm working on a lua library fot drawing simple 3d object, > as explain you before, the big problem is put the patches in the > correct geometrical order, > So, for the moment I have operate in this manner: > ... OK... I hope you understand that you are operating so far outside of Pipmak's primary scope here that I treat the particular problems you're encountering with low priority. > I have tryed (just for test) to enable depth buffer on SDL (before calling > SDL_SetVideoMode( width, height, bpp, flags ) > > using: > > SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); > > but it's not sufficient, because the behaviour isn't changed..... You need to glEnable(GL_DEPTH_TEST), too. But as I mentioned, I suspect that having the depth test enabled all the time will mess up (i.e. make invisible) a lot of things. glDepthFunc(GL_LEQUAL) may help somewhat in that case. -Christian |