-1

I am getting such a weird violation error by using the getAt() method. enter image description here I use the method in this order:

    OdDbBlockTablePtr       w_kOdBlockTablePtr ;
    bool  lbCreateDefaults = false;
    OdDb::MeasurementValue  lkMeasurement = OdDb::kEnglish;
    OdDbDatabasePtr pDb;
    // Datenbank initialisieren
    pDb = g_ExSystemServices.createDatabase(lbCreateDefaults, 
    lkMeasurement);

    // TABLE - Hold Ptr
    
    w_kOdBlockTablePtr = pDb->getBlockTableId().openObject(OdDb::kForWrite);
const wchar_t AcadBlockModelSpace[] = L "*MODEL_SPACE";

wstring lsModelSpace(AcadBlockModelSpace);
w_kOdModelSpaceBlockRecPtr = GetTableRecordIdFromName(lsModelSpace, (OdDbSymbolTablePtr&)w_kOdBlockTablePtr).safeOpenObject(OdDb::kForWrite);


OdDbObjectId K_TeighaClass::GetTableRecordIdFromName(wstring& psName, OdDbSymbolTablePtr& pkTablePtr)
{
    OdDbObjectId lkId;
    try {
        OdString lsOdName = psName.c_str();
        lkId = pkTablePtr->getAt(lsOdName);
    }

    catch (OdError& err)
    {

        DoOdError(err, NULL, NULL);
    }

    return lkId;
}

I would really appreciate if someone could help me. Thanks in advance

Zac Boussaid
  • 35
  • 1
  • 8
  • *Access* violation. Be accurate. – user207421 Feb 28 '22 at 09:02
  • That cast to `OdDbSymbolTablePtr&` looks very suspicious. – molbdnilo Feb 28 '22 at 09:26
  • @user207421 I really don't know how I should be more specific, I posted all the information I have and problem by running my code. If you need something specific just let me know – Zac Boussaid Feb 28 '22 at 09:28
  • @molbdnilo not at all i'm sure it works – Zac Boussaid Feb 28 '22 at 09:29
  • How can you be sure of that when your program is crashing? – molbdnilo Feb 28 '22 at 09:31
  • @molbdnilo because I tested the function GetTableRecordIdFromName with another smart pointer and it worked fine – Zac Boussaid Feb 28 '22 at 09:36
  • I've told you how to be more specific. *Access* violation. You've left out half the error message. – user207421 Feb 28 '22 at 09:37
  • @ZacBoussaid That proves nothing. If "smart pointer" refers to one of the standard ones, casting between different instantiations will lead to undefined behaviour. Please include the definitions of your types. (Also, checking that you don't have null pointers before using them for anything is not a waste of time.) – molbdnilo Feb 28 '22 at 09:45

1 Answers1

0

That's not weird at all. If you hover your mouse over pkTablePtr, you will almost certainly find that it is nullptr (or the debugger might report this as 0).

There's not enough information in your question to say why this might be, but since you are already running under the debugger you can walk through your code and find out.

try ... catch won't catch a hard error like this, by the way. For that, you need __try ... __except (supported on Windows only).

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48
  • pkTablePtr is not a nullptr. I#ll update my post so you can understand the load of pkTablePtr – Zac Boussaid Feb 28 '22 at 09:30
  • @ZacBoussaid The debugger doesn't agree with you. One of you is wrong, and it isn't the debugger. There is nothing in your post that proves `pkTablePtr` isn't null, or that assigns it any value at all. – user207421 Feb 28 '22 at 09:46
  • After 2 hour of struggling i want to inform you that you're right. All my smart pointers are set to nullptr. To change that lbCreateDefaults needs to bec hanged to true. ( If and only if true, the newly created database will be populated with the default set of objects (all tables, ModelSpace and PaperSpace blocks etc.) ) – Zac Boussaid Feb 28 '22 at 11:56
  • Cool, glad it's sorted. Time spent learning how to use the debugger better is rarely wasted. – Paul Sanders Feb 28 '22 at 14:21