[Gdal-dev] Null-Pointer in GDALOpen?
Tom Kazimiers
2voodoo at gmx.de
Mon Oct 22 15:01:48 EDT 2007
Hello,
now I understand what the purpose of the "Reply To All" button is :)
Mateusz Loskot schrieb:
> Tom Kazimiers wrote:
>> thanks for the replys.
>> Sure I do test against null - the posted code was just an excerpt :) -
>> thanks anyway.
>> And yes, the crash occurs within GDALOpen() - I put a MessageBox before
>> and after GDALOpen() - only the first one appeared, than the crash.
>> The file handle explanation looked promising but before this line is
>> arrived I still can open files plus after a restart it also does not work.
>
> Tom,
>
> It sounds strange. Perhaps you could post complete snippet of code,
> then it will be easier to investigate it.
Ok, here is a bigger part of it:
bool CGDALContainer::AddFile(const wchar_t * w_pszFileName)
{
// Convert wchar_t to char
const int newsize = wcslen(w_pszFileName);
char *pszFileName = (char *)malloc(newsize + 1);
int count = wcstombs(pszFileName, w_pszFileName, newsize);
if (count == 0 || count != newsize) {
FILE * pFile = _wfopen(L"PDAShpTool_ErrorLog.log",L"a");
fwprintf(pFile, L"Error: The Filename \"%s\" could not be
converted to Const Char *!\n", w_pszFileName);
fwprintf(pFile, L" Charactos before: %d Converted items:
%d\n", newsize, count);
fclose(pFile);
return false;
}
pszFileName[newsize] = '\0'; // one never knows...
GDALDataset *poDataset = NULL;
GDALAllRegister();
MessageBoxW(NULL, L"HA", L"DLL", MB_OK);
poDataset = (GDALDataset *) GDALOpen( "\a.tif" /*pszFileName*/,
GA_ReadOnly );
MessageBoxW(NULL, L"HA2", L"DLL", MB_OK);
if (poDataset == NULL) {
return false;
}
GDALRasterBand *poBand = poDataset->GetRasterBand( 1 );
...
...
return true;
}
>
>> The path "a.tif" is the full path of the file as this image is stored in
>> root directory of Windows CE 5.
>
> Do you mean that using file name only works like full path to root
> directory \, then it's wrong. It doesn't work this way under Windows CE.
>
> If you use only file name, it's assumed you open it from \My Documents,
> which is a default data location under Windows CE.
>
Thanks for this hint - strange enough that it worked until yesterday
evening with only the filename for the root directory.
One more thing is that if I put "a.tif" in to open it crashes - if I put
"\a.tif" in it does not crash - it just returns NULL and I
can handle this (besides that the null return is strange, also). The
error returned by CPLGetLastError() is:
CPLError: `.tif' does not exist in the file system
This error was without convertig from wchar_t to char - it was with
"\a.tif" inserted directly. It seems as if the const char * is not
received properly.
Like I said, I can not really imagine that the problem is really
GDALOpen as it worked until yesterday and I did not change the dll.
But the crash occurs there.
>> The last thing I tryed was to put "GDALAllRegister();" right befor
>> GDALOpen() - before this I did it in completely different function,
>> which I think, should work, too.
>> But also this change did it not...
>
> Another thing I'd suggest to check is to see if you have built GDAL with
> GTiff driver, means check if the GTiff driver is properly registered
> and available, in run-time.
>
At least returns
"GetGDALDriverManager()->GetDriverByName("GTiff")->GetDescription()":
GTiff
So I think it gets registered properly.
> p.s. Please, use Reply To All, so gdal-dev address is included.
> Otherwise, you reply only to post author, me in this case,
> but not the list.
>
> Cheers
I will do this in future mails, I did not know this. Thanks
bye
Tom
More information about the Gdal-dev
mailing list