mouseloc() crash: Bug in loadnode?

View: New views
7 Messages — Rating Filter:   Alert me  

mouseloc() crash: Bug in loadnode?

by Andrea Viarengo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Christian,

if you try this project:

main.lua
  version (0.27)
  title "test-mouse"
  startnode (1)

1.lua
  panel { " image.png",....}
  posx,posy=pipmak.mouseloc()
  pipmak.print(posx," ",posy)

Pipmak crash with access violation (this not happen with pipmak.clickloc() )

I'm investigated a little:

The access violation is caused by member-method thisCNode->mouseXYtoHV
which it isn't initialized as all of the methods of CNode
at time of calling mouselocLua()!  

  pipmakLuaLib.c:
    static int mouselocLua(lua_State *L)
       thisCNode->mouseXYtoHV(thisCNode, mouseX, mouseY, &h, &v);

This is the calling sequence which cause te error:
  
  nodes.c:
    CNode *loadNode(int nodeID)
      .....
      .....
      /* at this point mouseXYtoHV isn't initialized */  
      call pipmak_internal.loadnode from default.lua
           ....
           default.lua:  --now execution continue in lua
             luaDofile("node.lua")
              which call mouselocLua
                which call mouseXYtoHV   -->not defined: error!!!
      .....
      .....
      /* now mouseXYtoHV is initialized but it too late!!!*/
      case NODE_TYPE_PANEL:
        makePanelCNode(thisCNode);  //this initialize mouseXYtoHV !!!
      .....
      .....


I think it should be possible which the problem happen also with other functions...

I think you have to move the initializing of methods of CNode before calling
pipmak_internal.loadnode

It's very interesting how you have implemented OOP in C, I never seen before!

Andrea



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

Re: mouseloc() crash: Bug in loadnode?

by Christian Walther :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrea Viarengo wrote:

> 1.lua
>   panel { " image.png",....}
>   posx,posy=pipmak.mouseloc()
>   pipmak.print(posx," ",posy)
>
> Pipmak crash with access violation (this not happen with pipmak.clickloc() )
>
> I'm investigated a little:
>
> The access violation is caused by member-method thisCNode->mouseXYtoHV
> which it isn't initialized as all of the methods of CNode
> at time of calling mouselocLua()!

Good catch. You're right that there may be more bugs of that kind.

The problem is that I can't initialize the methods before running
node.lua because I don't know what kind of node it is yet.

The only simple solution I can imagine is returning (0, 0) or something
from pipmak.mouseloc() as long as thisCNode->complete == 0. Or perhaps
undefining pipmak.mouseloc altogether in that context would be even
better. Otherwise we'd have to redesign the whole node loading process.
Do you have a better idea?

Is there a real-life reason why you want to query the mouse location in
node.lua, or are you just trying to break things? Could what you're
doing be moved to onenternode?

  -Christian


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

Re: mouseloc() crash: Bug in loadnode?

by Andrea Viarengo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christian Walther <cwalther <at> gmx.ch> writes:

> Is there a real-life reason why you want to query the mouse location in
> node.lua, or are you just trying to break things? Could what you're
> doing be moved to onenternode?

Yes, I'm trying to build a contextual menu which appears on mouse location
when a right button event is trapped.

During my experiment I get the crash.
Probably, when you designed mouse methods you have thought which the
logical place where recall these was on onenternode(), and
this is right, perhaps it would be good specify in
the documentation that calling mouseloc in the body of the node return
insignificant values (after off-course, to have modified code to avoid crash)

I resolve my issue passing event.motion.x, event.motion.y from "C" to "lua"

Another thing regard mouseloc which isn't clear in the documentation:

On a panel which show an image 128x128 at resolution 640x480,
mouseloc/mouseclick return a couple of values from 0,0 to 128,128  and
not from 0,0 to 640,480 as someone could wrongly think.

This is an other reason for which Mouseloc it doesn't suit well for my
case.


I send a screenshot of what I am  doing.

Bye

Andrea




-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

contex-menu.jpg (48K) Download Attachment

Re: mouseloc() crash: Bug in loadnode?

by Christian Walther :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrea Viarengo wrote:
> Yes, I'm trying to build a contextual menu which appears on mouse location
> when a right button event is trapped.

There's no such thing as a "right button event" in Pipmak, and that's by
design. Don't assume that people have (or are willing to use) more than
one mouse button.

> During my experiment I get the crash.
> Probably, when you designed mouse methods you have thought which the
> logical place where recall these was on onenternode(), and
> this is right, perhaps it would be good specify in
> the documentation that calling mouseloc in the body of the node return
> insignificant values (after off-course, to have modified code to avoid
> crash)

Thinking about it again, I think that throwing an error would be the
best thing to do when that function is called on an incomplete node.

I don't feel comfortable with going through the documentation now and
marking which functions are useful to call during node loading and which
aren't. I'd rather keep this unspecified for the moment, because it may
change when node.lua files are run on other occasions in the future
(e.g. to build the project map).

> I resolve my issue passing event.motion.x, event.motion.y from "C" to "lua"

But that's not what pipmak.mouseloc is specified to return.

> Another thing regard mouseloc which isn't clear in the documentation:
>
> On a panel which show an image 128x128 at resolution 640x480,
> mouseloc/mouseclick return a couple of values from 0,0 to 128,128  and
> not from 0,0 to 640,480 as someone could wrongly think.

The documentation says "Returns two values, the coordinates of the mouse
pointer *in the coordinate system of the current node*." Two lines
above, it explains in more detail what that is. Any suggestions how that
can be made clearer? Should the detail description from
pipmak.clickloc() be repeated for pipmak.mouseloc()?

What sense would it make to return the mouse location in screen pixels
anyway? The only meaningful thing you could do with them is to divide
them by pipmak.screensize() to get relative values. The fullscreen
resolution/window size is an arbitrary user choice and should not matter
to your game/application logic. I don't even remember why I put
screensize into pipmak and not into pipmak_internal.

> This is an other reason for which Mouseloc it doesn't suit well for my
> case.

I don't have a solution ready for what you want to achieve, but I have
the uneasy feeling that you're trying to force square pegs into round
holes. That's not necessarily a bad thing - progress comes from that,
see the pipmak.setfullscreen case - but still...

  -Christian


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

Re: mouseloc() crash: Bug in loadnode?

by Andrea Viarengo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There's no such thing as a "right button event" in Pipmak,

Oh, I forgot that Apple mice have only 1 button...

So, you haven't Contextual menus in MacOSX ?  I have remained to system7  which haven't them, but I thought  was introduced  in next OS releases...

> What sense would it make to return the mouse location in screen pixels anyway?

Infact have no sense, because if you change resolution mouseloc haven't change their values...
Ok, you are right, clear what I told.

As you will have been able to see from the screenshot, I got an contextual menu working in Windows.
checking event.button.button   1=left 3=right

Apart the absence of right mouse on Mac, do you think this type of menu was a bad idea?
I thought that menu which appear only when it need and change its contents its content based on the context was less invasive respect a fixed menu attached to the window or the desktop...
 
Have you some idea to active it without a right button (how you can simulate this button in Mac? You use "Apple button"? )

Andrea



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

Re: mouseloc() crash: Bug in loadnode?

by Urs Holzer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> I thought that menu which appear only when it need and change its
> contents its content based on the context was less invasive respect a
> fixed menu attached to the window or the desktop...

I think this kind of menu could be even useful in gameplay: With an
object you can do different things: kick it, talk with it, take it,
apply another object etc. So, it would be quite intuitive if a context
menu appears when you click on such an object.



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel

Re: mouseloc() crash: Bug in loadnode?

by Christian Walther :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrea Viarengo wrote:
> Oh, I forgot that Apple mice have only 1 button...
>
> So, you haven't Contextual menus in MacOSX ?  I have remained to
> system7  which haven't them, but I thought  was introduced  in next OS
> releases...

Yes, there are contextual menus on Mac OS X (they're activated using
right-click or ctrl-click), and no, not all Apple mice have one button,
but that's not the point. I'm a proponent of the one-button mouse not
because I think multiple buttons are not useful, but because I think
they are less intuitive. Grasping the concept of the multi-button mouse
is more intellectual work than grasping the concept of the one-button
mouse. It's a farther abstraction from the real world. In the real world
it doesn't matter whether I push a button using my index finger or my
middle finger.

I don't want people to make games where I have to learn about arbitrary
mouse button assignments first (one such game that I recently played the
demo of is Ankh), therefore Pipmak exposes a one-button-mouse interface
to the game developer.

> Apart the absence of right mouse on Mac, do you think this type of menu
> was a bad idea?
> I thought that menu which appear only when it need and change its
> contents its content based on the context was less invasive respect a
> fixed menu attached to the window or the desktop...

No, seems reasonable. I can't really judge how well it works before
seeing it in action, and maybe comparing it to what I would have come up
with. But as I mentioned, I don't have a very concrete vision of how
these things are going to work. It'll grow as I go.

I'm interested in seeing what you come up with, but be assured that I
will have my own ideas, and whether or not they will be compatible with
yours remains to be seen...

> Have you some idea to active it without a right button

Left mouse button, when the "node background" or "selection" or whatever
tool is selected, maybe?

  -Christian


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Pipmak-Devel mailing list
Pipmak-Devel@...
news://news.gmane.org/gmane.games.devel.pipmak.devel
https://lists.sourceforge.net/lists/listinfo/pipmak-devel