Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOpenForRead returning closed objects? #1

Open
steelmats opened this issue Nov 29, 2017 · 6 comments
Open

QOpenForRead returning closed objects? #1

steelmats opened this issue Nov 29, 2017 · 6 comments

Comments

@steelmats
Copy link

steelmats commented Nov 29, 2017

Thank you for this repo, it is awesome! However, I am experiencing stability issues when batch processing a large amount of blocks. I am suspecting that QOpenForRead can have part in this since they return a closed object:

   public static DBObject QOpenForRead(this ObjectId dboId, Database db)
    {
        using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
        {
            return trans.GetObject(dboId, OpenMode.ForRead);
        }
    }

The using statement will call to close the object before returning it, and it is no longer guaranteed that the object can be used. See this post on the Autodesk forum.

@luanshixia
Copy link
Owner

Thank you for raising this concern. The using statement should only be able to close the Transaction object, meaning the transaction is done and the DBObject object is populated and ready to use. Since this is open for read, read operations should be fine with the returned object. Just make sure do not try to set any properties. I have been using this method intensively in my own project and not a single issue has come to my sight.

@steelmats
Copy link
Author

According to Autodesk, the objects that were opened using Transaction.GetObject will be closed when disposing of the transaction:

Once you have a Transaction or OpenCloseTransaction object, use the GetObject method to open an object stored in the database for read or write. The GetObject method returns a DBObject which can be cast to the actual object type it represents.

All open objects opened during a transaction are closed at the end of the transaction.

I agree it works anyway, and I haven't had any problems until I start processing a large amount of dynamic blocks. It is possible that my problems derive from something else, but I just want to make sure this is not the issue.

@luanshixia
Copy link
Owner

luanshixia commented Nov 30, 2017

My guess is this description in the documentation was inherited from the C++ ObjectARX. In ObjectARX, objects opened with transactions share same address space with the AutoCAD kernal. This is obviously not the case in managed .NET application, where opened objects are just copy. Nonetheless, I am happy to help solve any problems you may have.

@luanshixia
Copy link
Owner

You can easily verify whether this is the issue by putting your read operation inside a transaction and see if the issue is gone.

@steelmats
Copy link
Author

I tried using an overload for QOpenForRead that works as QOpenForWrite, but the mysterious error messages did not go away. So I am convinced my problems come from another source and this issue can be closed. But since you are offering help, would you mind take a look at my code if I put together a simplified VS solution? Perhaps via email (or channel of your choice), since its not relevant here anymore.

@luanshixia
Copy link
Owner

You can send it to [email protected]. Also please share the AutoCAD version, and any test .dwg you are using.

luanshixia pushed a commit that referenced this issue Jun 19, 2018
Updated Acad references from Nuget, Change to .Net 4.7.1
Repository owner deleted a comment from yannvr Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants