Wimp_LoadTemplate Handle error
Pages: 1 2
Martin Avison (27) 1494 posts |
I have been investigating a weird occasional error when a Wimp_LoadTemplate seems to return a ‘Handle is either illegal or has been closed’ error. In essence, the program does the usual
From the ROOL source in Wimp06 it appears that: Wimp_LoadTemplate The only possible situation when this error could be raised is when the RMA does not have enough space for the Template file, so Wimp_LoadTemplate has to use OS_GBPB to read data directly from the open file. However, for some reason an error is returned from OS_GBPB. The error has only been seen when run during boot on RISC OS 4.02 under VRPC, and then only occasionally. An additional complication is that I do not have 4.02, as my VRPC-AdjustSA does not want to run it. It could be caused by… Has anyone any suggestions how I can discover why it is happening? |
Jon Abbott (1421) 2651 posts |
I’ve seen that exact error in a game that inadvertently tried loading the template to page zero. It worked fine up to RO 4 with no errors reported, beyond that it reported the error you describe – it had me stumped for days. |
Martin Avison (27) 1494 posts |
A buffer for the largest window (as found by the initial LoadTemplates) is obtained (from RMA using XOS_Module,6 – which is checked for errors!), and that is used for all the actual LoadTemplates & CreateWindows, and then freed. So I do not think that can be the problem, but an interesting thought, and I will try to ensure it is valid. |
Colin Ferris (399) 1818 posts |
Not sure what you mean by VRPC not running RO4.02 – I would have thought it would have to – to start up? |
Steffen Huber (91) 1953 posts |
VRPC-AdjustSA has RISC OS 4.39 “from the startup”. Traditionally, it is not made easy to give different RO versions to any version of VRPC, be it DL or Adjust or SE. |
Martin Avison (27) 1494 posts |
Yup – that is the version I now have. I have had VRPC for many many years, although it only gets occasional use. I am sure that one of my earlier versions would run 4.02, which was sometimes useful for testing, but I think one of the ‘upgrades’ removed that ability in favour of 4.39. I did ask on the VRPC mailing list if it was possible to run 4.02 on AdjustSA, but had no responses. All very inflexible. I know RPCEmu will run 4.02, but I have never managed to get networking to work. |
Colin Ferris (399) 1818 posts |
If you have still have a copy of the compressed ro4.02 rom – you should be able to dual boot. On the Windows side – inside the VRPC dir there should be a RomSets Dir. Create a new one – ie RISCOS4_02. Put inside the ro4.02 ‘rom’ file – as a note – the ‘rom’ seems to be able to called anything – so calling it ro402 – is not a bad idea – might save some confusion. Now go into the Win ‘Models’ dir. Open up the new dir. Load up the Model/cfg file – (might be worth making a copy first). [Rom] filename = “Romsets\xxxx” xxx= what name you gave the dir inside the RomSets dir. Note ie at the top of the file just before – it seems that you can use the | to [PhysicalBus] |
Steffen Huber (91) 1953 posts |
Have you actually tried this with VRPC-Adjust? I am fairly sure that the encryption of the ROM images changed between “standard” and “adjust” VRPC versions so they are not interchangeable. But I can put it on the list of things to try “real soon now”… |
Martin Avison (27) 1494 posts |
@Colin: Thanks for the suggestions – that is essentially what I did. It opens the window, but the main part is white. And it seems to just sit there looping. @Steffen: Are the VRPC ROMs encrypted? If so and they are different, that would explain the problems. I am using the ROM from the £5 ‘Virtually free RO4 for Emulators’ download from 3QD Developments. But it does not work on my VRPC … now from 3QD Developments. Wonderful. I think I will try RPCEmu, and put up with the lack of networking. |
Colin Ferris (399) 1818 posts |
The VRPC ‘rom’ from what other have said – when loaded – clips the front off – and then un-squeezes it. You need the ‘rom’ file from VRPC. It will be interesting if Steffen can confirm – whether it will work or not. The one you have is for the RPCemu. |
Martin Avison (27) 1494 posts |
But it is advertised and sold as ‘for emulators’ without being specific. |
Steffen Huber (91) 1953 posts |
I can at least say that the opposite direction does not work – VRPC-DL cannot use the Adjust ROM from VRPC-AdjustSA. |
Martin Avison (27) 1494 posts |
I have just received clarification from Aaron, who said: For my immediate purpose, RPCEmu will suffice to run 4.02. |
Rick Murray (539) 13850 posts |
Newer emulator doesn’t run older OS version? Strange… |
Steffen Huber (91) 1953 posts |
I think it is just wrong to think about the VirtualAcorn products as “emulators”. It is a closed box system that runs the bundled version of RISC OS on selected hosts. It provides little of the usual flexibility one expects from emulators like switching OS versions. Still, I am often using it in preference to RPCEmu because of multiple HostFS mounts and easy networking on Windows. Although the no-longer working mouse sync means that using it is much more annoying than it was previously. |
Martin Avison (27) 1494 posts |
@Steffen: I agree totally with everything you said. It is a shame development stopped many years ago. |
Martin Avison (27) 1494 posts |
Before this thread was sidetracked on my problems running RO4.02 on VRPC-AdjustSA, it was about Wimp SWIs OpenTemplate, Load Template and CloseTemplate. I suggested earlier…
If programs have any Wimp_Polls between OpenTemplate and CloseTemplate, I have now confirmed by a test that this can cause severe problems for programs – and the problems are occasional, depending on timing. But they could affect programs started at boot in a consistent way. For example… This applies whether the Templates file is in Resources, loaded in to RMA, or read from file. I am amazed that this has not come to light before, but I suppose that unless the Templates are complex it is easiest to put all the code together – and probably before polling starts. I will try to compose a warning and add it to the PRM WiKi documentation. What I still do not understand is why my user has these symptoms, but there is no Poll between Open and Close Template. Something must be closing the file, or corrupting the Wimp workspace, and I cannot (yet) see how. |
Rick Murray (539) 13850 posts |
It has. Niall’s Wimp2 preemptive thingy had to include a hack to disable preemption around the calls to Open and Close the templates. It’s pretty obvious why – if you look at the documentation, the OpenTemplate call opens the template but does not return any handle. As we know the Wimp is smoke and mirrors, it’s going to be obvious that there’s probably only one file handle internally. A quick look at the source shows this to be exactly the case. It probably hasn’t come to light before because there are probably very few people who poll with a template file open (everybody knows that polling with files open isn’t a great idea), and it would require the eventuality of two programs starting up in exactly that right way with respect to each other that it triggers the problem. |
Rick Murray (539) 13850 posts |
Uh, hang on… PRM 3-165 actually says in the description of Wimp_OpenTemplate:
So software should not be polling with a template open (as it can’t be sure that anything else won’t try to use those calls). In which case:
Is because the programs are wrong. |
Martin Avison (27) 1494 posts |
Yes, I am aware of that. But it should be clearer that it is a global restriction, not just for the task. And to the uninitiated it is not obvious that implies no polling. In my case, there are no Polls involved, yet the problem symptom indicates something has happened to the file after at least 50% of the LoadTemplates have been done. I am waiting for further details from the user which I hope will help further diagnosis. |
Dave Higton (1515) 3534 posts |
Curious. I always understood, from the first time that I read it, that this was a global restriction; also, I understood the implication of no polling. |
Rick Murray (539) 13850 posts |
As Dave has already said… The documentation for the SWI specifies one at a time so it was most logically going to be a global restriction (notwithstanding the number of applications using multiple template files at the same time is likely to be miniscule). |
Andrew Conroy (370) 740 posts |
Was this something you already knew, or did you have to look it up? Unfortunately the StrongHelp manual doesn’t include this warning. I wonder how many programmers routinely work from the SH manuals rather than the paper version (I know I do, I only refer to the paper version if the SH manual isn’t clear), so I think we can be a bit forgiving of authors who have unwittingly fallen foul of this without shouting “You’re wrong!” at them. |
Rick Murray (539) 13850 posts |
Since I’ve been programming since the end of the eighties (my first Wimp programs didn’t even use templates as FormEd was so awful), I can’t really answer that. I guess it was just something that I assumed because, as I said above, the OpenTemplate SWI does not return a handle, and pretty much everything else in RISC OS is global state so it stands to reason that this would be too.
Don’t forget that those of us with modems often participated in multiuser discussions and forums and mostly Fidonet (I was 2:254/86.1, a point off of Steve Pursey’s Arctic BBS), and it’s probably there that I picked up the most information. Probably Justin. Remember also the magazines used to do type in listings, tutorials, and so on.
I apologise. I thought it was just common knowledge that you don’t hold any global state (file handles, current font, directory scan, FP registers1, etc etc etc) across a Wimp poll as there is exactly zero guarantee that another program won’t mess with those things in your absence. 1 The Wimp saves some of the FP registers if you ask it. RISC OS 2 didn’t… Actually those who first started with RISC OS 2 are probably used to doing things the hard way. ;-) |
Colin Ferris (399) 1818 posts |
CLOSE #0 in BASIC – Just had a look – two progs I use – do a CLOSE with no check for 0. *CLOSE – trips up some progs :-( MSG_Trans what does a Close 0 do there? What are Internet progs supposed to do over a Poll? |
Pages: 1 2