I have a button with a Pressed Event handler that runs a Method and it works fine, but when I run that Method by clicking on a rectangle object with a Mouse Down command, the project app crashes. Why is that?
what line does it crash on?
You may want to put your code in mouseup instead.
What sort of crash is it, where is the crash, and can we see the method and the contents of the Pressed and MouseDown handlers.
Is you code in a Method that is called by both Events ?
(or code duplicated in each event ?)
Share a sample for inspection or we will see a shower of guessings and, at the end, the cause could be something exotic no one guessed before.
This is the screen where the magic is happening.
On the left I added 3 images with an invisible rectangle object on top of it which I gave the Event handler Mouse Down which has this code: app.CreateEmptyDatabase
The top white button has the Event Handler Pressed and has that same code.
Pressing the invisible rectangle runs the Method correctly, but then crashes the app. Pressing the button does the same but does not crash the app.
Mouseup is not doing anything.
The error message in the Window that pops up is:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000a3a67fcb6948 â 0x000023a67fcb6948 (possible pointer authentication failure)
Exception Codes: 0x0000000000000001, 0x0000a3a67fcb6948
Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process: exc handler [2438]
Where is the rest of the crash?
Looks like you are trying to use something invalidated. What and how you got it, only you can find without sharing some kind of sample to reproduce it.
This is a picture of a plane crash. What caused the engine fail? (take that with humor )
You must return True in MouseDown for MouseUp to fire.
What version of Xojo are you using?
Thanks, this works, The app is not crashing any longer.
Ideally you should report this to Xojo along with a sample project as the Xojo framework should not crash. It should raise an exception.
Just because you added âreturn trueâ in mousedown?
Yes, that was the only reason itâs working now. The crash was a little weird one though. Normally when pushing the Open Collection Button for example, the Method for opening a database fires correctly, I then choose the database which opens without any problem and from that point I can start using my app.
When I did the same by clicking on the Picture (second from the left), the Method still opened the database correctly, but then after 1 second my app crashed. Now it doesnât do that any longer.
Because this thread is mentioning Mouse Down and Mouse Up events ⊠When I started programming, I figured I wanted something to happen when I clicked ON an object. Soon I realized that putting the action in MouseDown was like stepping on a land mine. Once the mouse was down, the action was committed. Eventually, I understood that a âclickâ is two actions, and putting the desired event on the mouse up provides a degree of âforgivenessâ. I could mouse down on something, then realizing it was premature, I could slide off and not trigger the Mouse Up.
Interestingly, the objects MouseUp is dependent on involvement by mouse down - the requirement to return True. Iâm sure thatâs well-documented somewhere.
Yes, I highlight my buttons on mousedown, and set a flag there too. I use mouseexit to clear that flag and reset the highlight, and donât do the real action in mouseup unless that flag is set.
And yes, that True requirement is well documented.
Since decades, it has been a known fact that double clicks are defined differently on Mac and Windows. On Mac, a double click happens on mouse up; on Windows, itâs on mouse down.
So even the OS may define when a click should be registered.