Errors and Caret handling
Chris (121) 472 posts |
I had a frustrating time recently trying to work out why a simple syntax error in one of my BASIC programs caused the whole system to crash when it was reported with Wimp_ReportError. It turned out to be caret-related (I think) – a dialogue box was open that had the input focus at the point when the syntax error was reached. My generic error-handling procedure reported the error and terminated the task. This then resulted in a cascade of aborts on data transfer, which I’m guessing is because the Wimp was trying to move the caret back to my task’s main window after the task was terminated? Is that likely to be the correct explanation? Does that mean I’m doing something stupid with my caret-handling? Or does my error-handling need to do some more cleaning-up before closing the task down? |
Rick Murray (539) 13851 posts |
It would seem odd if the Wimp was mucking up placing carets.
You neglect to mention – what language, what libraries? Maybe some library code is trying to do something dumb? Oh, and are you using a recent ROM with the cut’n’paste stuff? Does it behave the same way on an older (say, stable release) Wimp? Just in case you’ve exposed an edge case…
I’d be inclined to simply stick an “ You could also try Wimp_SetCaretPosition, -1 to forcibly disown the caret; see if that makes any difference? |
Alan Adams (2486) 1149 posts |
As you’re using BASIC, I assume you have ON ERROR OFF as the first line of the error handler. That generally stops recursive calls of the error handler if it enncounters errors. |
Chris (121) 472 posts |
It’s BASIC, and not using any special libraries. It is a recent ROM, with cut-and-paste, though the problem is present with earlier ROMs. I’m sure it’s me doing something stupid, but I guess I was hoping there was some gotcha that might be well known that would explain the errors.
I already tried that – still get the crashes. And putting
This is the relevant code:
|
Stuart Swales (1481) 351 posts |
It is safest though to do ON ERROR OFF before ANY processing:
|
Chris (121) 472 posts |
Thanks. Even with that improvement, it’s still crashing. I’m going to have to do some digging to see what’s going wrong. I have a window open that has the input focus. I then open a transient dialogue box over this window, created using Wimp_CreateMenu. This has a writeable icon in it, so grabs the focus. When I click on OK, the dialogue box is closed with Wimp_CloseWindow. It all works as expected, except if there’s an error in the code run when the dialogue box actually does its stuff. In that case, once the error is reported (with the dialogue box still open), all hell breaks loose after the error handler has reported it, despite the fact it should have closed down the task. If I edit the templates so that there are no writeable icons in the dialogue box, and hence no focus grabbing, then the crashes don’t take place. Something must be trampling over something somewhere, but I can’t see where that might be at the moment. |
Stuart Swales (1481) 351 posts |
Presuming that you’ve used a ’modern’+ Wimp_Initialise, you should pass the task handle in R0 to Wimp_CloseDown, and ‘TASK’ in R1. + for values of ‘modern’ >= RISC OS 3.00 |
Andy Vawer (5817) 28 posts |
The Wimp shouldn’t crash and burn that badly from what you’ve described, so I’ve been trying to replicate this to find out why. I’m using the following piece of thrown-together code:
The first window has an input focus; this is passed to the dialogue. Then a syntax error is generated opening an error box and then the program exits as per your snippet. It doesn’t kill the Wimp for me here though on either the old or latest versions. If the program’s short could you post it in full here, or feel free to email it to me (andy [atsign] vawer dot com) and I’ll see if I can find out what the underlying nasty is. Thanks Andy |
Chris (121) 472 posts |
Yeah, it definitely shouldn’t be doing that, so there must be something else in my program that’s creating instability. It’s quite a big one, so I think I’ll start by stripping it down to see if I can create a more manageable lump of code that still demonstrates the issue. Thanks a lot for the email address – if I get totally stuck, I might wing that over to you if you’re happy to take a look. |
Chris (121) 472 posts |
Hmm. I just copied your program, created a couple of templates as described, and ran it here. And it crashed when I provoked the syntax error! So that’s odder. I’m running OS 5.27 from December, IOMD, on RPCEmu (Mac). I’m beginning to wonder if there’s something up with my setup, since I also had strange input focus behaviour with the latest Paint builds that no one else could replicate. Not sure what the best way to investigate this further is, though. |
Jeffrey Lee (213) 6048 posts |
I’ve had problems with StrongED crashing in the past, seemingly due to caret-related issues (I think when StrongED tried to restore the caret to a window that no longer exists?). I think they went away when I upgraded StrongED. Something to check, if you’re using StrongED on your machine. If that doesn’t fix it, a Debugger exception dump should help us track down the problem (although that feature doesn’t cope very well with continuous aborts – it’ll keep overwriting the log file, so the first abort, which is often the most useful, will quickly get lost). Also it isn’t totally useful on IOMD because there isn’t enough space in the ROM for the build system to fit the debug symbols (it’ll work, you just won’t get any function names for ROM code) |
David Pitt (3386) 1248 posts |
RPCEmu could be an issue. I have failed to derive the templates file that Andy’s test require. If someone emails me a test I will try here. pittdj at pittdj dot co dot uk And investigate the Paint thing. The latest macOS RPCEmu 0.9.2 build, patch 4, is here |
Alan Adams (2486) 1149 posts |
I’ve copied this code, and run it on rpi running 5.23, rpi running 5.24 and ARMX6 running 5.25. All fail to crash. |
Andy S (2979) 504 posts |
Chris you’re not having much luck with input focuses! It’s a very long shot but I wonder if this has a common cause with your problem with the Sprite File window focus… |
Alan Adams (2486) 1149 posts |
I created a template file with two templates. The first created has 5 icons. Number 4 is a menu icon. The second has two icons, of which the second is a menu icon. (I’m not sure whether they have to be menu items – I think not). click menu over the first window’s menu icon and the second window opens. click on the menu item here and the window closes. edit: I’ve emailed the files |
Alan Adams (2486) 1149 posts |
I ran the test here from within a StrongED window, version 4.69f11. no crash. I occasionally get wierdness here if Pipedream windows are iconised when an application with the caret quits. Pipedream quits (if I remember right) with an error about “input focus window not found”. It may have been fixed in the latest Pipedream, which I switched to not long ago. |
David Pitt (3386) 1248 posts |
I have the test files now, thanks. I get “Syntax error at line 29” on macOS RPCEmu without anything untoward happening, the Error box clears normally. |
Alan Adams (2486) 1149 posts |
It’s looking that way. Do you have any add-on things running? |
Chris (121) 472 posts |
Well, I’m baffled! I’ve checked I’m on the latest versions of RPCEmu and StrongED, and Andy’s minimal program still crashes reliably, bringing everything down with it. My !Boot sequence is pretty minimal – I’m not running anything strange that I’m aware of, and have stripped everything non-vanilla out of Resources just in case. Here’s the top end of the Debugger’s report following a crash. I exited RPCEmu after the first of the aborts was reported. If the rest of the dump is useful, let me know and I’ll post here too
|
David Pitt (3386) 1248 posts |
Just because RPCEmu seems fine on this 2013 iMac it does not preclude other Mac hardware having some little trick up its sleeve to derail the works. The interpreter build might be worth a try, it is slower but is a simpler proposition. If it is thought the that the current OS5 could be harbouring something unfortunate then a second very vanilla instance of OS5 can be made comprising only the ROM and HD4 image. |
Julie Stamp (8365) 474 posts |
Did you get this sorted? The ShareFS logon box has writeable icons, and I can often make it crash in a similar way if the Name field is empty but the password field is filled. |
Chris (121) 472 posts |
I never got the bottom of it, I’m afraid. As it’s quite an obscure effect, I put it down to a quirk of RPCEmu, but when I get time I’ll try with a totally fresh install, to eliminate anything random that might be causing it. Out of interest, are you using RPCEmu, or a machine running RISC OS natively? |
Julie Stamp (8365) 474 posts |
Yes I’m on RPCEmu as well at the moment, 0.9.3. I just tried the above test code (making a template with test having 5 writable icons and dialog having 2) but the syntax error didn’t make it crash. |