Tuesday, November 28, 2023
Home3D ModelingDoes CAPI assist multi-threading? - SketchUp SDK

Does CAPI assist multi-threading? – SketchUp SDK


When outputting Structure, I need to generate mannequin viewports in a number of threads.

image

I obtained exception from SketchupViewerAPI.dll

image

LOInitialize();
// Initialize thread pool
std::threadpool executor{ 4 };
// pageInfos format
// {"page_name"=>[upper_left_pt,lower_right_pt,page_index,page_scale]}
std::vector<std::string> members = pageInfos.getMemberNames();
std::vector<std::future<void>> outcome;

for (int i = 0; i < members.measurement(); i++) {
    // Add activity
    outcome.emplace_back(executor.commit([pageInfos, members, skp_file,i]()-> void {
        std::string page_name = members[i];
        Json::Worth pageInfo = pageInfos[page_name];

        LOAxisAlignedRect2D rect;
        rect.upper_left.x = pageInfo[0][0].asDouble();
        rect.upper_left.y = pageInfo[0][1].asDouble();
        rect.lower_right.x = pageInfo[1][0].asDouble();
        rect.lower_right.y = pageInfo[1][1].asDouble();

        LOSketchUpModelRef mannequin = SU_INVALID;
        SUResult res = LOSketchUpModelCreate(&mannequin, skp_file.c_str(), &rect);
        if (res == SU_ERROR_NONE) {
            SU(LOSketchUpModelSetCurrentScene(mannequin, pageInfo[2].asInt()));
            SU(LOSketchUpModelSetRenderMode(mannequin, LOSketchUpModelRenderMode_Raster));
            SU(LOSketchUpModelSetScale(mannequin, pageInfo[3].asDouble()));
            SU(LOSketchUpModelSetLineWeight(mannequin, 1.0));
            printf("%d %s okn", i, page_name.c_str());
            SU(LOSketchUpModelRelease(&mannequin));
        }
        else {
            printf("%d %s (%.4f , %.4f) (%.4f , %.4f) %dn",i, page_name.c_str(),
                rect.upper_left.x, rect.upper_left.y, rect.lower_right.x, rect.lower_right.y, res);
        }
        return;
    }));
}
// wait all activity
for (int i = 0; i < members.measurement(); i++)
    outcome[i].get();
LOTerminate();


We can not translate Chinese language from a picture. Please put up an English translation of the exception message.

Is skp_file the identical for all viewports ?

How would a number of threads be capable to learn from the identical file (or it’s illustration in reminiscence) and be capable to write to the identical reminiscence illustration of a LayOut doc, on the identical time ?


Additionally I don’t see that you simply’ve added the viewport to the LayOut doc throughout the loop.
See: LODocumentAddEntity()

Typically, with the LayOut APIs, the entity must be first connected to a doc earlier than it’s properties could be modified. In any other case the entity’s properties get set to default values.

A latest macOS function does enable translating from a picture:

SpC hanging board typesetting reducing okay

Japanese SPC hanging board structure facade Aok

12SPC hanging board typesetting okay

3 brand index diagram okay

4 coloration terrazzo brick typography aircraft okay

15 coloration terrazzo brick typography reducing okay

6 coloration terrazzo brick typography okay

Scene No. 732ok

8 lamp positioning map okay

9 Flooring structure okay

On this case, I’m unsure that helped.

Unhandled exception at 0x00007FFFE69EBBF5(SketchUpViewerAPI.dll)(SketchUpTest.exe):There’s a battle when learn Handle 0xFFFFFFFFFFFFFFFF.
SketchUpTest is my program.

Sure, It’s identical file.

In my creativeness, multithreaded studying must be okay, as a result of it doesn’t contain writing.

If the identical file exists in SketchupViewAPI.dll, and the SKP file is parsed solely as soon as and there may be an operation to write down to reminiscence, the API will not be relevant to a number of threads.

You’re proper. My focus is on the LOSketchUpModelCreate.
And I would like check it, as a result of the perform is time-consuming.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments