29 June 2020, 13:42 | #1 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Why printf in hook function freezes everything?
I have another question with regards to hooks. I have added a hook to a STRING_KIND gadget. Everything works fine if I handle the input from as IDCMP_GADGETUP message. However if I put a printf in the hook function everything will freeze up (even mouse pointer, need to restart). Why does this happen? Do I need to use some command before and after the printf so that this does not happen.
|
29 June 2020, 13:50 | #2 |
Registered User
Join Date: Nov 2010
Location: South Wales
Age: 46
Posts: 934
|
what would it be printing too ?
|
29 June 2020, 14:05 | #3 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
In CLI (shell).
Just to give an example, if I put printf in hook function as follows every freezes; Code:
ULONG editfield(struct Hook *hook, struct SGWork *obj, ULONG *msg) { printf("something"); } Code:
while(run){ ... if(msgClass == IDCMP_GADGETUP){ printf("something"); } ... |
29 June 2020, 14:12 | #4 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,333
|
Maybe the hook function is called by input.device, not your task? Try having the hook function signal your task (which is a Process and so can call DOS functions) and do the printf from there.
|
29 June 2020, 14:21 | #5 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
From the examples I found on the internet the hook is simply used to send messages back through IDCMP. Like that it works.
So is the hook function for STRING_KIND only to determine when to raise IDCMP messages back to solution? For example I also tried to edit another gadget, but this also freezes the moment I try to refer to some function I have written. Edit: Just to clarify, I can do everything through IDCMP. The reason I am asking the question is that I did not understand why it freeze when I was trying to do same things directly from the hook. From what I understand (now), this will fail as the hook code is not running as part of my process and therefore everything breaks when I think I am modify memory dedicated to my process when in reality this would not be the memory of my process. I suppose this is where the hook h_Data comes in. Last edited by Sim085; 29 June 2020 at 14:43. |
29 June 2020, 19:39 | #6 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Quote:
No, this cannot work. The best you can do is to print a string over the serial port. Or use a low-level debugger like COP. The string hook is called from intuition when receiving input events, and thus within the intuition input handler, which keeps many intuition resources locked. Printing requires (through many indirection layers) locking the same resources, so this blocks forever. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How would I hook the Amiga up to one of these? | Pyromania | support.Hardware | 19 | 20 February 2020 15:37 |
Integers vs floats (FFP/Sing/Doub) + printf() | guy lateur | Coders. Asm / Hardware | 63 | 18 July 2017 17:57 |
Hook | jcmoorehead | support.Games | 2 | 27 June 2004 17:48 |
Hook problem | Walker | support.Games | 5 | 13 June 2002 22:19 |
Looking for Hook manual | Dime333 | request.Old Rare Games | 2 | 11 January 2002 15:46 |
|
|