asl/getfile requester ( Solved )

This forum is for general developer support questions.
mcleppa
Posts: 27
Joined: Sun Sep 04, 2011 5:00 pm
Contact:

asl/getfile requester ( Solved )

Post by mcleppa »

I have a problem when using asl filerequester in my program. My requester is a multiselect, and works fine when I only select files, but if I only choose drawers, the program crashes and I get a recoverable alert.
What I have found out is that the crash happens when i use ´FreeAslRequest()´ .

If I don´t free the requester I am okay, but it should not be like that.
Anyone experienced the same or have an explanation on this.
Last edited by mcleppa on Sat Jan 11, 2014 5:01 pm, edited 3 times in total.
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1483
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: asl/getfile requester

Post by tonyw »

Without looking up the docs, the first things I would do:

1) Use the debug kernel. It will spit out more useful information when you have a crash. It might even make your program crash earlier, which would be useful.
2) Capture the crash log somehow. The best way is to capture it on a serial terminal.
3) Add the options "serial" and "munge" to the os4 command line, eg "os4_commandline = 'serial munge debuglevel=0'".
4) Do whatever you do to cause the crash then look at the DAR in the crash log.

If the DAR is 0x00000000 (or thereabouts), then you have accessed a null pointer (and you will see ABADCAFE in one or more registers).
If the DAR is 0xDEADBEEF (or thereabouts), then you have accessed some memory after it has been freed.
If the DAR is 0xCCCCCCCC (or thereabouts), then you have tried to free a Node a second time.

If you post the first part of the crash log here (not all the system data or library information, please!), we can help you debug it.
cheers
tony
mcleppa
Posts: 27
Joined: Sun Sep 04, 2011 5:00 pm
Contact:

Re: asl/getfile requester

Post by mcleppa »

Thanx, here's the Crashlog and I try some more debugging :D
Crash log for task "music-tagger"
Generated by GrimReaper 53.2
Crash occured in module kernel at address 0x0140F0DC
Type of crash: program exception

Register dump:
GPR (General Purpose Registers):
0: 01415ED0 01C984C0 00000000 01C980F0 01000009 59A933A0 5A84E668 01DAA3D4
8: 24422024 0140CBE4 5A84E4EC 00000000 01CA97C4 5A9008A0 00000001 00000000
16: 00000000 00000000 8008003F 00000000 5950C738 8500350F 85003505 5A84E3E8
24: 168E6448 1645AE70 00000001 5950C424 5A84E668 5A84E440 01CA97C4 5BB21800


FPR (Floating Point Registers, NaN = Not a Number):
0: nan 254 134 0
4: 0 770.8 30.8 0
8: 0 2.78132e-309 770.8 30.8
12: 1025 165 0 0
16: 0 0 0 0
20: 0 0 0 0
24: 0 0 0 0
28: 0 0 0 0

FPSCR (Floating Point Status and Control Register): 0x82004000


SPRs (Special Purpose Registers):
Machine State (msr) : 0x0002F030
Condition (cr) : 0x24422028
Instruction Pointer (ip) : 0x0140F0DC
Xtended Exception (xer) : 0x20000005
Count (ctr) : 0x01415EBC
Link (lr) : 0x0143567C
DSI Status (dsisr) : 0x04000000
Data Address (dar) : 0x7FE54F48



680x0 emulated registers:
DATA: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ADDR: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
FPU0: 0 0 0 0
FPU4: 0 0 0 0



Symbol info:
Instruction pointer 0x0140F0DC belongs to module "kernel" (HUNK/Kickstart)

Stack trace:
native kernel module kernel+0x0000f0dc

PPC disassembly:
0140f0d4: 80430018 lwz r2,24(r3)
0140f0d8: 8003000c lwz r0,12(r3)
*0140f0dc: 7c1a03a6 mtsrr0 r0
0140f0e0: 80030008 lwz r0,8(r3)
0140f0e4: 7c1b03a6 mtsrr1 r0
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1483
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: asl/getfile requester

Post by tonyw »

Hmmm, not much useful info there. That's the problem with the GR's crashlog - it's too late. The output to the serial port (before the GR requester appears) often has more information. You can get it on another machine via a serial cable or store it somewhere using Sashimi.

You could post the code here if you like. Use the "Hidden text" tags so it fits on the page.
cheers
tony
mcleppa
Posts: 27
Joined: Sun Sep 04, 2011 5:00 pm
Contact:

Re: asl/getfile requester

Post by mcleppa »

I have stripped down the program to a single window and a button to open the filerequester.

Sourcecode is here:
source :
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/window.h>
#include <proto/layout.h>
#include <proto/button.h>
#include <proto/getfile.h>

#include <classes/window.h>

#include <gadgets/getfile.h>

#include <reaction/reaction_macros.h>

enum
{
GID_MAIN=0,
GID_LOAD,
GID_FILEREQUESTER,
GID_LAST
};

enum
{
WID_MAIN=0,
WID_REQUESTER,
WID_LAST
};

enum
{
OID_MAIN=0,
OID_REQUESTER,
OID_LAST
};

int main(void)
{

struct Window *windows[WID_LAST];
struct Screen *screen;
struct MsgPort *AppPort;

Object *gadgets[GID_LAST];
Object *objects[OID_LAST];

screen=IIntuition->LockPubScreen(NULL);
if ( screen )
{
/* make sure our classes opened... */
if (!ButtonBase || !WindowBase || !LayoutBase )
return(30);
AppPort = (struct MsgPort *)IExec->CreateMsgPort();
if (AppPort)
{
/* Create the window object. */
objects[OID_MAIN] = WindowObject,
WA_Title, "GetFile Test",
WA_Width, 200,
WA_Height, 50,
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_Opaqueness, 255, /* Initial opaqueness on opening (0..255) */
WA_OverrideOpaqueness, FALSE, /* Override global settings? (TRUE|FALSE) */
WA_FadeTime, 250000, /* Duration of transition in microseconds */
WA_NewLookMenus, TRUE,
WA_IDCMP, IDCMP_MOUSEBUTTONS,
WINDOW_AppPort, AppPort,
WINDOW_Position, WPOS_CENTERMOUSE,
WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,

LAYOUT_SpaceOuter, TRUE,
LAYOUT_DeferLayout, TRUE,
LAYOUT_BevelStyle, BVS_GROUP,

LAYOUT_AddChild, gadgets[GID_LOAD] = ButtonObject,
GA_ID, GID_LOAD,
GA_RelVerify, TRUE,
GA_Text, "Load",
ButtonEnd,
CHILD_WeightedHeight, 0,
CHILD_WeightedWidth, 0,

LayoutEnd,
WindowEnd;

/* Object creation sucessful? */
if (objects[OID_MAIN])
{
/* Open the window. */
windows[WID_MAIN] = (struct Window *) RA_OpenWindow(objects[OID_MAIN]);
if ( windows[WID_MAIN] )
{
ULONG wait, signal = (1L << AppPort->mp_SigBit);
ULONG done = FALSE;
ULONG result;
UWORD code;

/* Obtain the window wait signal mask. */
IIntuition->GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);

/* Input Event Loop */
while (!done)
{
wait = IExec->Wait( signal | SIGBREAKF_CTRL_C );

if ( wait & SIGBREAKF_CTRL_C )
{
done = TRUE;
}
else
{
while ( (result = RA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
{
switch (result & WMHI_CLASSMASK)
{
case WMHI_CLOSEWINDOW:
done = TRUE;
break;

case WMHI_GADGETUP:
switch (result & WMHI_GADGETMASK)
{

case GID_LOAD:

gadgets[GID_FILEREQUESTER] = GetFileObject,
GA_ID, GID_FILEREQUESTER,
GA_RelVerify, TRUE,
GETFILE_DoMultiSelect, TRUE,
GETFILE_TitleText, "Select File",
GETFILE_Drawer, "RAM:",
GETFILE_Pattern, "#?",
End;

IIntuition->IDoMethod (gadgets[GID_FILEREQUESTER], GFILE_REQUEST,NULL);
IIntuition->DisposeObject(gadgets[GID_FILEREQUESTER] );

break;

}

break;
}
}
}
}
}
IIntuition->DisposeObject(objects[OID_MAIN]);
}
IExec->DeleteMsgPort(AppPort);
}
}
IIntuition->UnlockPubScreen(NULL,screen);
return (RETURN_OK);
}
User avatar
trixie
Posts: 411
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: asl/getfile requester

Post by trixie »

@ mcleppa
What I have found out is that the crash happens when i use ´FreeAslRequest()´
You seem to be mixing up different things. If you create the file requester as a BOOPSI object (through getfile.gadget) and invoke it via a method, you shouldn't need AllocAslRequest() / FreeAslRequest() at all. Getfile.gadget wraps object-oriented code around asl.library and handles the asl data structure allocations/deallocations automatically and internally: DisposeObject(gadgets[GID_FILEREQUESTER]) calls FreeAslRequest() for you, so any subsequent call to the function will naturally produce a crash because memory for the requester data structure has already been freed.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
mcleppa
Posts: 27
Joined: Sun Sep 04, 2011 5:00 pm
Contact:

Re: asl/getfile requester

Post by mcleppa »

Hei, sorry about my mixup, my example here uses getfile.gadget and I free it using DisposeObject(), as I believe should be right according to autodocs.
But the same crash happens when I use asl requester and use AllocAslRequest() / FreeAslRequest().
mcleppa
Posts: 27
Joined: Sun Sep 04, 2011 5:00 pm
Contact:

Re: asl/getfile requester

Post by mcleppa »

I had to open this post again, since I now believe there is a bug in asl.

I have used an example from amigaos wiki documentation and the same fault happens with this.
The following happens: when using the 'DoMultiSelect' option it causes the system to get a 'Recoverable Alert'. It happens when you select more than one drawer. But if you start up program again after the 'Alert' and select the same amount of drawers, it works ok. But selecting more drawers next time again will cause the same 'alert'. The program is printing the output to screen and sometimes it prints only 'rubbish' on some Drawer/File names. The crash happens always when calling AslFreeRequest().

Here is the sourcecode: http://home.lyse.net/arildaarbakk/programs/asl.c

Would appreciate if anyone more experienced could have a look into this.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 534
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland
Contact:

Re: asl/getfile requester

Post by salass00 »

@mcleppa

Is the alert this one?
#define AN_FreeTwice 0x01000009UL /* Freeing memory already freed */

I compiled and ran your program and it seemed to work fine on my beta system at least. There was a bug fixed in asl.library V53.48 (19.8.2013) that might be the cause of your problem.

In the future it might be a good idea to state the alert code rather than just saying that there was an alert as it may be useful information in finding the problem.

Edit:

Just tried on my non-beta system and it produced the AN_FreeTwice alert so yes it is likely the bug I fixed in asl.library V53.48.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 534
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland
Contact:

Re: asl/getfile requester

Post by salass00 »

@mcleppa

I just managed to reproduce FreeAslRequest() crash. It seems there may be more than one bug involved here...

I don't have time to look into it right now but I will later.
Last edited by salass00 on Tue Sep 17, 2013 5:05 pm, edited 1 time in total.
Post Reply