English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 29 June 2020, 13:42   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 707
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.
Sim085 is offline  
Old 29 June 2020, 13:50   #2
S0ulA55a551n
Registered User
S0ulA55a551n's Avatar
 
Join Date: Nov 2010
Location: Rhondda, Wales
Age: 43
Posts: 585
what would it be printing too ?
S0ulA55a551n is offline  
Old 29 June 2020, 14:05   #3
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 707
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");
}
But the following works ok;

Code:
while(run){
   ...
   if(msgClass == IDCMP_GADGETUP){
      printf("something");

   }
   ...
(I removed code to simplify example).

Quote:
Originally Posted by S0ulA55a551n View Post
what would it be printing too ?
Sim085 is offline  
Old 29 June 2020, 14:12   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,174
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.
mark_k is offline  
Old 29 June 2020, 14:21   #5
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 707
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.

Quote:
Originally Posted by mark_k View Post
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.
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.
Sim085 is offline  
Old 29 June 2020, 19:39   #6
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 452
Quote:
Originally Posted by Sim085 View Post
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.

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.
Thomas Richter is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:12.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.08342 seconds with 15 queries