GM_SetFeatureClassEnabled() crashes GlobalMapper

Toni HeimalaToni Heimala Global Mapper UserPosts: 15
edited February 2012 in SDK
For some reason I don't see all vector layers enabled when launching my application. So I tried iterating through all the available FeatureClassInfo's like this (prints removed):
for (GM_FeatureClassType_t8 featureClassType = 0; featureClassType < GM_FeatureClass_NumTypes; ++featureClassType)
    FeatureClass_t16 featureClass = 0;
    FeatureClass_t16 featureClassMax = 0;

    switch (featureClassType)
        case GM_FeatureClass_Area:
            featureClass = AFC_MIN;
            featureClassMax = AFC_MAX_BUILTIN;
        case GM_FeatureClass_Line:
            featureClass = LFC_MIN_LINE;
            featureClassMax = LFC_MAX_LINE;
        case GM_FeatureClass_Point:
            featureClass = PFC_MIN_POINT;
            featureClassMax = PFC_MAX_POINT;

    for (; featureClass < featureClassMax; ++featureClass)
        GM_FeatureClassInfo_t* featureClassInfo = NULL;
        const GM_Error_t32 errorCode = GM_GetFeatureClassInfo(featureClass, featureClassType, featureClassInfo);
        const GM_Error_t32 setErrorCode = GM_SetFeatureClassEnabled(featureClass, featureClassType, true);

errorCode is 2 (GM_Error_InvalidParam) for every value of featureClass and featureClassType.
SetFeatureClassEnabled() goes through for featureClass 0-6 (featureClassType == 0), reports error code 1 (GM_Error_InvalidLayer) for featureClass 7 and crashes for featureClass 8 with following message:
FeatureArea.h - 1050
Version: v1.37
Build Time: Jan 17 2012 20:55:40


  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2012
    I see a couple of problems. For your call to GM_GetFeatureClassInfo you need to have actually allocated a structure to pass to that, not just pass in a NULL, otherwise you will always get an GM_Error_InvalidParam error. Call it as follows:

    GM_FeatureClassInfo_t featureClassInfo;
    GM_Error_t32 errorCode = GM_GetFeatureClassInfo( featureClass, featureClassType, &featureClassInfo );

    Check that to see if a non-empty description comes back. If so that means you have a valid type and not one of the gaps in the set of types. If you have that, then call GM_SetFeatureClassEnabled. Note that function does not return an error code, it returns the previous enabled state of that type. So a return of 1 means that the type had been turned on before, 0 means it had been off.

    Let me know if I can be of further assistance.


    Global Mapper Guru
Sign In or Register to comment.