clGetPlatformInfo() causes segmentation fault in dynamically linked application?

Hello,
I am using Qt for developing my application and it has a class which loads libraries at run time.
For the following code I am getting a segmentation fault.


QLibrary *MyOpenCL::openCLLibrary = NULL;

bool MyOpenCL::loadOpenCL()
{
    if(openCLLibrary)
        return  true;

    QLibrary *lib = new QLibrary("OpenCL");
    if(!lib->load())
        return false;

    bool result = false;
    typedef cl_int (*MyPlatorms)(cl_uint, cl_platform_id *, cl_uint *);
    MyPlatorms pobj = (MyPlatorms) lib->resolve("clGetPlatformIDs");
    if(pobj)
    {
        cl_uint nplatforms = 0;
        cl_uint myerr = pobj(INT_MAX, NULL, &nplatforms);
        if((myerr == CL_SUCCESS) && (nplatforms > 0))
        {
            cl_platform_id *mplatforms = new cl_platform_id[nplatforms];
            {
                const cl_uint csize = nplatforms;
                myerr = pobj(csize, mplatforms, &nplatforms);
            }

            typedef cl_int (*MyPlatformInfo)(cl_platform_id, cl_platform_info, size_t, void *, size_t *);
            MyPlatformInfo pinfoobj = (MyPlatformInfo) lib->resolve("clGetPlatformInfo");
            if(pinfoobj)
            {
                size_t size;
                for(unsigned int i = 0; i < nplatforms; i++)
                {
                    size = 0;
                    myerr = pinfoobj(mplatforms[i], CL_PLATFORM_VERSION, 0, NULL, &size);//line A
                    if(size < 1)
                        continue;

                    char *ver = new char[size];
                    {
                        const size_t csize = size;
                        myerr = pinfoobj(mplatforms[i], CL_PLATFORM_VERSION, csize, ver, &size);//line B
                    }
...
}

When I am debugging at line B it jumps to line A and shows the Segmentation Fault error.
I have spent 6 hours figuring this one out and so far I have had no luck.
I am running Windows7 with MinGW compiler and my ATI 7670m has OpenCL 1.1 drivers.
Please suggest me how to solve my problem?

Hey there,

Can you tell me how many platforms your system is returning, and what the setup is? Basically need to rule in/out whether the ICD could be causing the problem or not. (EG. do you have Intel CPU with Intel OpenCL SDK + AMD APP SDK installed?)

Thanks,
-Neil.

[QUOTE=neil_henning;30210]Hey there,

Can you tell me how many platforms your system is returning, and what the setup is? Basically need to rule in/out whether the ICD could be causing the problem or not. (EG. do you have Intel CPU with Intel OpenCL SDK + AMD APP SDK installed?)

Thanks,
-Neil.[/QUOTE]

Hello Neil,

I am getting 1 platform.
I have ATI Radeon 7670m GPU and Intel 2nd gen i5 processor.
The drivers are from ATI hence only 1 platform is shown.
The SDK I am using is APP from AMD, however I feel it has nothing to do with my problem since I am not linking the .lib from SDK as I want dynamic linking.
Can you provide any possible cause for my problem?

Very weird indeed! Your code looks fine at a glance - just for the sake of debugging, can you try instead of using runtime linking, actually link at compile time? Would be useful to rule that in/out at this stage.

I have tested some samples on my laptop with static linking and they all work fine.
It is only with run time linking that I am getting these problems.
Maybe Qt is not resolving the functions properly?