MCPcopy Create free account
hub / github.com/defold/defold / LoadFromBufferInternal

Function LoadFromBufferInternal

engine/modelc/src/modelimporter_jni.cpp:570–686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570static jobject LoadFromBufferInternal(JNIEnv* env, jclass cls, jstring _path, jbyteArray array, jobject data_resolver)
571{
572 dmLogDebug("CreateJavaScene: env = %p\n", env);
573
574 dmJNI::ScopedString j_path(env, _path);
575 const char* path = j_path.m_String;
576
577 const char* suffix = strrchr(path, '.');
578 if (!suffix) {
579 dmLogError("No suffix found in path: %s", path);
580 ThrowModelLoadException(env, "No file suffix in path");
581 return 0;
582 }
583 suffix++; // skip the '.'
584
585 jsize file_size = env->GetArrayLength(array);
586 jbyte* file_data = env->GetByteArrayElements(array, 0);
587
588 dmModelImporter::Options options;
589 dmModelImporter::Scene* scene = dmModelImporter::LoadFromBuffer(&options, suffix, (uint8_t*)file_data, file_size);
590
591 if (!scene)
592 {
593 dmLogError("Failed to load %s", path);
594 env->ReleaseByteArrayElements(array, file_data, JNI_ABORT);
595 ThrowModelLoadException(env, "Failed to load model");
596 return 0;
597 }
598
599 if (scene->m_LoadError && scene->m_LoadError[0])
600 {
601 ThrowModelLoadExceptionFromScene(env, scene, "Failed to load model");
602 dmModelImporter::DestroyScene(scene);
603 env->ReleaseByteArrayElements(array, file_data, JNI_ABORT);
604 return 0;
605 }
606
607 bool resolved = false;
608 if (data_resolver != 0 && dmModelImporter::NeedsResolve(scene))
609 {
610 jclass cls_resolver = env->GetObjectClass(data_resolver);
611 jmethodID get_data = env->GetMethodID(cls_resolver, "getData", "(Ljava/lang/String;Ljava/lang/String;)[B");
612
613 for (uint32_t i = 0; i < scene->m_Buffers.Size(); ++i)
614 {
615 if (scene->m_Buffers[i].m_Buffer)
616 continue;
617
618 const char* uri = scene->m_Buffers[i].m_Uri;
619 jstring j_uri = env->NewStringUTF(uri);
620
621 jbyteArray bytes = (jbyteArray)env->CallObjectMethod(data_resolver, get_data, _path, j_uri);
622 if (env->ExceptionCheck()) {
623 dmLogError("JNI ExceptionCheck failed:");
624 env->ExceptionDescribe();
625 env->ExceptionClear();
626 dmModelImporter::DestroyScene(scene);
627 env->ReleaseByteArrayElements(array, file_data, JNI_ABORT);

Calls 12

ThrowModelLoadExceptionFunction · 0.85
DestroySceneFunction · 0.85
NeedsResolveFunction · 0.85
ResolveBufferFunction · 0.85
LoadFinalizeFunction · 0.85
ValidateFunction · 0.85
dmLogGetLevelFunction · 0.85
DebugSceneFunction · 0.85
CreateJavaSceneFunction · 0.85
LoadFromBufferFunction · 0.70
SizeMethod · 0.45

Tested by

no test coverage detected