Global Mapper v25.0

GM_Error_InvalidLayer

fxrazno1
fxrazno1 Global Mapper UserTrusted User
edited February 2011 in SDK
Hi
In my application I am loading 10 layers of ecw maps.
When I am running my application Thur my application developer environment
I can open and close layers with any problem.
When I run the exe file outside the developing environment and try to close the 10 layers I loaded I get an error "GM_Error_InvalidLayer" in layer 6 and 7.
What could be the problem ?
Thanks
Raz

Comments

  • global_mapper
    global_mapper Administrator
    edited January 2011
    Raz,

    It sounds like somewhere your list of layer handles is being corrupted. Do you get the same issue if you run the sample application?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited January 2011
    No I don't.
  • global_mapper
    global_mapper Administrator
    edited January 2011
    It sounds like maybe your layer handles are being corrupted somewhere or maybe you have an uninitialized variable or something (a common release vs. debug problem) that is messing things up. You might log the layer handles are you load them and then again as you close them to make sure they are the same.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited January 2011
    Hi
    When I run the application from the developer I get this pointers to the 10 layers of ecw files I am loading:
    $9BC3D60
    $9C674F8
    $9C6CD50
    $9C735E8
    $9C79ED8
    $9C807C8
    $9C87100
    $9C8DA38
    $9C94370
    $9C9ACA8

    But when I run the exe file outside the developer I get this pointers:
    $9B7D008
    $C3010E8
    $C3062D0
    $C30BB40
    $C311510
    $C317060
    $C31CF18
    $C322E10
    $C328D28
    $C32EC40

    It looks like something is wrong with the memory allocation.

    Can you explain a bit about the GM_LoadLayerList function:
    GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_LoadLayerList
    (
    const char* aFilename,
    GM_LayerHandle_t32** aLayerList,
    uint32* aNumLoadedLayers,
    GM_LoadFlags_t32 aLoadFlags
    );
    is the aLayerList a pointer to a list of pointers ?
    Also does this function allocate memory for the layer and is there a way to get the size of the allocated memory for each layer ?
    Do I have to allocate memory for each layer I load ?

    Also I checked the list of handles to the layers before closing the layers and it looks the same as when I open them.

    Thanks
    Raz
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited January 2011
    Hi
    I checked memory allocation when loading a layers and closing them.
    When I load 10 layers I can see an increase in PF Usage in the windows task manager but when
    closing all of the layers the pf usage does decrease. it stays the same. It seem the the memory allocated for
    the layer was not released.

    Thanks
    Raz
  • global_mapper
    global_mapper Administrator
    edited January 2011
    Raz,

    A layer handle is just a pointer to dynamic memory allocated in the SDK. You won't necessarily get the same layer handle values between runs. What is important isn't the actual value of the layer handles but whether or not you still have the same layer handles when you make the GM_CloseLayer call as you got from the GM_LoadLayerList call.

    The GM_LoadLayerList function does internally allocate memory for the list of layers loaded by the function and return the address of that allocated list. You need to copy the layer handle values from the returned list into your own storage upon return. See the C++ sample application for how to do this. Or if possible I would suggest just using the GM_MapWindow class from the C++ sample application as it already does this correctly.

    You might not immediately get all of the memory back when opening and then closing a bunch of layers. There are internal caches of data that will stay allocated so they can be used again later if needed.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi
    If i loaded a ecw file to a layer, closed the layer and then load the same file again I will get a diffrent handle, but
    when I closed to layer does it free the memory for the file loaded or when I open the file again after closing it just the value of the pointer changes ?
    Thanks
    Raz
  • global_mapper
    global_mapper Administrator
    edited February 2011
    Raz,

    The memory associated with just the layer will be freed, although some shared buffers that might be re-used by other layers might still be allocated. You don't need to do anything extra, just calling GM_LoadLayerList and later GM_CloseLayer is all that you need to do to clean up.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi Mike
    I am developing my application with Delphi7.
    Can you think of a reason why I have no problem when running my application from the the Delphi developer environment against running the application outside Delphi ?
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    I have 12 maps in the ecw format.
    I have an application with two buttons.
    button1 - load the 12 files.
    button2 - closes the layers with GM_CloseLayer
    I press button1 and wait for the layers to load.
    After that I press button2 and wait for the layers to close.
    After pressing button1 and then button2 for several of time (7 to 8 times)
    I get an error after pressing button1 that says:

    Unexpected error loading file C:\Maps\isr5km_7.ecw
    Out of memory.
    GlobalMapperInterface.cpp - 11350
    Version: v1.34
    Build Time: Sep 22 2010 15:20:06

    Can you figure out what is the problem ?
    Thanks
    Raz
  • global_mapper
    global_mapper Administrator
    edited February 2011
    I'm really not familiar with Delphi. Are there perhaps some Delphi DLLs that you need to provide or are you not copying all of the files from the 'bin' folder of the SDK to your .exe deployment location? Check the what_to_distribute.txt file from the 'doc' folder of the SDK for a list of files that you need to distribute.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi
    All the files I need to run my application are in the folder. I load maps and close and every thing work great.
    But when I run the application and try to open and close ecw files several of times I get the error. I think the problem is related
    to the ecw files. Can you check the error I got "out of memory" in line 11350 of GlobalMapperInterface.cpp ?
    Can you check this problem by trying to open and close the same ecw layers several times ?
    Thanks
    Raz
  • global_mapper
    global_mapper Administrator
    edited February 2011
    The "out of memory" error that you are seeing just means that a dynamic memory allocation failed somewhere in the load of a layer. Can you first try updating to the latest SDK build from http://www.globalmapper.com/GlobalMapperSDK_v136_beta.zip and see if you get the same error? Do you know if you get the error in the included C++ sample application or just in your application?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi
    I updated the SDK. Same problem.
    What is the language the SDK was developed ?
    I think that the problem is how dynamic memory is allocated in Delphi verse the Language the SDK was written.
    Do you know any Delphi developer that used the SDK ?
    If so can you give is contact detail so I can consult him.
    Also in the GM_LoadLayerList function the first parameter is the file name to load.
    It is a pointer to a char. What is the string type ? is a null terminated string ?
    Is it possible to manage the memory allocation of the SDK Thur my application ?
    Thanks
    Raz
  • global_mapper
    global_mapper Administrator
    edited February 2011
    Raz,

    The SDK is developed in C++ (Visual Studio 2008). There shouldn't be any issues with how memory is allocated though as all memory allocated by the SDK is de-allocated by the SDK, the calling application doesn't have to worry about that so long as they call the proper functions in the SDK.

    When you call GM_LoadLayerList, are you copying the list of layer handles out of the returned list into your own structure? You would need to do this as the list of layers returned by the function is in a temporary list that will be overwritten the next time you call GM_LoadLayerList, so you need to copy the layer handles out when you get them.

    The char* is a standard C-style string, which is just the address of a NULL-terminated string of 1-byte characters.

    I'm not aware of any developers using Delphi. The vast majority of SDK developers use C++, C#, or VB.NET, with a handful of Java users through JNI.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi
    I think I found the problem.
    In the function that loads the maps I use a local variable called "Temp_Layers"
    and pass it to the GM_LoadLayerList and then copy the pointers in the Temp_Layers array to a global variable called "Layers_List".
    This cause the problem as I described earlier.
    If I pass GM_LoadLayerList the "Layers_List" parameter instead of the "Temp_Layers" parameter and check there is no problem !!!
    I guess that is because the "Layers_List" parameter is defined as a global parameter that is not destroyed when the application leave the function that load the maps.
    I guess that as you said some thing is wrong with the list of layers I am saving.
    I will check and try do understand what is wrong but if you any suggestions I would love to hear.
    Just to be sure the parameter that is send to the GM_LoadLayerList should be an (array of GM_LayerHandle_t32) that its size is unknown ?
    I defined the "Temp_Layers" as:

    Temp_Layers:array of GM_LayerHandle_t32;
    I am sending to the GM_LoadLayerList function the address of this array.
    Is this good ?

    Thanks
    Raz

    If I load a set of 12 ecw maps by opening a gmw file
  • global_mapper
    global_mapper Administrator
    edited February 2011
    Raz,

    What you should be passing to GM_LoadLayerList is a reference to a value to hold the address of a list of GM_LayerHandle_t32 values to be allocated by the SDK. Once you get that address back you then need to iterate through the list of loaded layers and copy each layer handle into your own structure. I'm not sure how to do this in Delphi, but there should be a way to increment the memory pointer returned by the pointer size (4 bytes in the case of the 32-bit SDK) to keep getting the next value.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • fxrazno1
    fxrazno1 Global Mapper User Trusted User
    edited February 2011
    Hi Mike
    I have found the problem.
    I had to define the "Temp_Layers" list outside the load function as a global variable instead has a local variable that exist only
    inside the function.
    I guess the SDK needs the "Temp_Layers" list to exist in the memory until the application is destroyed.
    Thanks for you help and patience , I appreciate it.
    Raz