I need to check if an image is supported by the installed datatypes, before I use it in GUI. So I thought to use the NewDTObject, and I wrote the checkImageDatatype() method to test it. Below you can see the code.
Although that this works great on AmigaOS 3 68k code, the AmigaOS 4 PPC version crashes the system at the NewDTObject() line.
BOOL check_path_exists(char *path) { const BPTR lock = Lock(path, SHARED_LOCK); if (lock) { UnLock(lock); return TRUE; } return FALSE; } BOOL checkImageDatatype(STRPTR filename) { if (check_path_exists(filename)) { Object *dtObj; dtObj = NewDTObject(filename, DTA_SourceType, DTST_FILE, DTA_GroupID, GID_PICTURE, TAG_DONE); if (dtObj) { DisposeDTObject (dtObj); return TRUE; } } return FALSE; }
Then I tried to change the method with the following, but unfortunately, on AmigaOS 4 PPC version it crashes at the ObtainDataType() line again.
BOOL checkImageDatatype(STRPTR filename) { BOOL result = FALSE; BPTR lock; struct DataType *dtn; if((lock = Lock(filename, SHARED_LOCK))) { if((dtn = ObtainDataType(DTST_FILE, (APTR) lock, TAG_END))) { const struct DataTypeHeader *dth = dtn->dtn_Header; printf("Description: %s\n", dth->dth_Name); printf(" Group: %s\n", GetDTString(dth->dth_GroupID)); if (dth->dth_GroupID == GID_PICTURE) { result = TRUE; } ReleaseDataType(dtn); } UnLock(lock); } return result; }
Any idea why the above works fine on AmigaOS 3 but crashes on AmigaOS 4? Anything I could check?
The issue is solved. I forgot to register the DataTypesIFace, that's why it was crashing only on OS4.
Found that issue thanks to Andy Broad who was kind to point me that way. Thanks Andy.