浏览代码

prototype fix

The issue is that, create UI in Update (like in TestFei.cs) will cause crash. this is just a prototype fix: only latch2 part is useful. we will look into this issue later when having time
/zxw-fix_crash
xingweizhu 3 年前
当前提交
728df288
共有 3 个文件被更改,包括 106 次插入8 次删除
  1. 33
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  2. 78
      Samples/UIWidgetsSamples_2019_4/Assets/Script/TestFei.cs
  3. 3
      Samples/UIWidgetsSamples_2019_4/Assets/Script/TestFei.cs.meta

33
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


namespace uiwidgets {
std::thread::id gfx_worker_thread_id;
int worker_set = 0;
fml::RefPtr<UIWidgetsPanel> UIWidgetsPanel::Create(
Mono_Handle handle, UIWidgetsWindowType window_type, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, window_type, entrypoint_callback);

size_t height, float device_pixel_ratio,
const char* streaming_assets_path,
const char* settings) {
fml::AutoResetWaitableEvent latch2;
// std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker([&latch2]() -> void {
latch2.Signal();
});
latch2.Wait();
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());

surface_manager_->ClearCurrent();
fml::AutoResetWaitableEvent latch;
std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
[&latch, &gfx_worker_thread_id]() -> void {
gfx_worker_thread_id = std::this_thread::get_id();
latch.Signal();
});
latch.Wait();
if (worker_set == 0)
{
fml::AutoResetWaitableEvent latch;
//std::thread::id gfx_worker_thread_id;
UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
[&latch]() -> void {
gfx_worker_thread_id = std::this_thread::get_id();
latch.Signal();
});
latch.Wait();
worker_set = 1;
}
gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
gfx_worker_thread_id, [this](const auto* task) {

78
Samples/UIWidgetsSamples_2019_4/Assets/Script/TestFei.cs


using UnityEngine;
using UnityEngine.UI;
namespace UIWidgetsSample
{
public class TestFei : MonoBehaviour
{
private float curTime = 0.0f;
private int totalNum = 10;
private bool isOk = false;
public static bool needwaiting = false;
private void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
this.isOk = true;
}
if (!this.isOk)
{
return;
}
//if (needwaiting)
//{
// return;
//}
if (this.totalNum <= 0)
{
return;
}
this.curTime += Time.deltaTime;
if (this.curTime < 0)
{
return;
}
this.curTime = 0;
this.totalNum--;
//needwaiting = true;
//for (int i = 0; i < 10; i++)
{
GameObject gameobject = new GameObject();
GameObject newCanvas = new GameObject();
Canvas c = newCanvas.AddComponent<Canvas>();
c.renderMode = RenderMode.WorldSpace;
newCanvas.AddComponent<CanvasScaler>();
newCanvas.AddComponent<GraphicRaycaster>();
var canvasTransform = c.GetComponent<RectTransform>();
canvasTransform.anchorMin = new Vector2(0, 0);
canvasTransform.anchorMax = new Vector2(0, 0);
canvasTransform.sizeDelta = new Vector2(800, 800);
GameObject panel = new GameObject("RawImage");
var rectTransform = panel.AddComponent<RectTransform>();
rectTransform.anchorMin = new Vector2(0, 0);
rectTransform.anchorMax = new Vector2(1, 1);
rectTransform.offsetMin = new Vector2(0, 0);
rectTransform.offsetMax = new Vector2(0, 0);
panel.AddComponent<CanvasRenderer>();
panel.AddComponent<HoverSample>();
panel.transform.SetParent(newCanvas.transform, false);
newCanvas.transform.SetParent(gameobject.transform, true);
}
}
}
}

3
Samples/UIWidgetsSamples_2019_4/Assets/Script/TestFei.cs.meta


fileFormatVersion: 2
guid: 3e9daa87a52a47e488207acb4a2a0bd0
timeCreated: 1645414930
正在加载...
取消
保存