|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.IO;
|
3 | 4 | using System.Linq;
|
4 | 5 | using UnityEngine;
|
|
9 | 10 | using VoltstroStudios.UnityWebBrowser.Core;
|
10 | 11 | using VoltstroStudios.UnityWebBrowser.Core.Engines;
|
11 | 12 | using VoltstroStudios.UnityWebBrowser.Communication;
|
| 13 | +using VoltstroStudios.UnityWebBrowser.Helper; |
12 | 14 | using VoltstroStudios.UnityWebBrowser.Shared;
|
13 | 15 | using VoltstroStudios.UnityWebBrowser.Shared.Core;
|
14 | 16 | using VoltstroStudios.UnityWebBrowser.Shared.Popups;
|
@@ -51,6 +53,11 @@ public void Initialize(int width, int height)
|
51 | 53 | {
|
52 | 54 | try
|
53 | 55 | {
|
| 56 | +#if UNITY_EDITOR |
| 57 | + // Enable native collection leak detection with full stack traces |
| 58 | + Unity.Collections.NativeLeakDetection.Mode = Unity.Collections.NativeLeakDetectionMode.EnabledWithStackTrace; |
| 59 | +#endif |
| 60 | + |
54 | 61 | // Start timing the initialization
|
55 | 62 | initializationTimer = System.Diagnostics.Stopwatch.StartNew();
|
56 | 63 | initStartTime = Time.realtimeSinceStartup;
|
@@ -333,17 +340,76 @@ public void Dispose()
|
333 | 340 | {
|
334 | 341 | if (isInitialized)
|
335 | 342 | {
|
336 |
| - // TODO: Implement proper disposal |
337 |
| - // webBrowserClient?.Dispose(); |
| 343 | + Debug.Log("[VoltUWBAdapter] 🧹 Starting UWB disposal..."); |
| 344 | + |
| 345 | +#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX |
| 346 | + // Unsubscribe from events first |
| 347 | + if (webBrowserClient != null) |
| 348 | + { |
| 349 | + try |
| 350 | + { |
| 351 | + webBrowserClient.OnLoadFinish -= OnLoadFinishHandler; |
| 352 | + webBrowserClient.OnLoadStart -= OnLoadStartHandler; |
| 353 | + Debug.Log("[VoltUWBAdapter] ✅ Event handlers unsubscribed"); |
| 354 | + } |
| 355 | + catch (Exception ex) |
| 356 | + { |
| 357 | + Debug.LogWarning($"[VoltUWBAdapter] ⚠️ Error unsubscribing events: {ex.Message}"); |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + // Dispose WebBrowser components |
| 362 | + if (webBrowserUI != null) |
| 363 | + { |
| 364 | + try |
| 365 | + { |
| 366 | + // WebBrowserUIFull should handle its own disposal |
| 367 | + UnityEngine.Object.DestroyImmediate(webBrowserUI); |
| 368 | + Debug.Log("[VoltUWBAdapter] ✅ WebBrowserUIFull destroyed"); |
| 369 | + } |
| 370 | + catch (Exception ex) |
| 371 | + { |
| 372 | + Debug.LogWarning($"[VoltUWBAdapter] ⚠️ Error destroying WebBrowserUIFull: {ex.Message}"); |
| 373 | + } |
| 374 | + } |
| 375 | + |
| 376 | + // Destroy GameObject |
| 377 | + if (uwbGameObject != null) |
| 378 | + { |
| 379 | + try |
| 380 | + { |
| 381 | + UnityEngine.Object.DestroyImmediate(uwbGameObject); |
| 382 | + Debug.Log("[VoltUWBAdapter] ✅ UWB GameObject destroyed"); |
| 383 | + } |
| 384 | + catch (Exception ex) |
| 385 | + { |
| 386 | + Debug.LogWarning($"[VoltUWBAdapter] ⚠️ Error destroying GameObject: {ex.Message}"); |
| 387 | + } |
| 388 | + } |
| 389 | + |
| 390 | + // Clear references |
| 391 | + webBrowserClient = null; |
| 392 | + webBrowserUI = null; |
| 393 | + uwbGameObject = null; |
| 394 | +#endif |
| 395 | + |
| 396 | + // Stop timers |
| 397 | + initializationTimer?.Stop(); |
| 398 | + navigationTimer?.Stop(); |
338 | 399 |
|
339 | 400 | IsActive = false;
|
340 | 401 | isInitialized = false;
|
341 |
| - Debug.Log("[VoltUWBAdapter] Volt Unity Web Browser disposed"); |
| 402 | + Debug.Log("[VoltUWBAdapter] ✅ Volt Unity Web Browser disposed successfully"); |
| 403 | + } |
| 404 | + else |
| 405 | + { |
| 406 | + Debug.Log("[VoltUWBAdapter] 💡 UWB already disposed or not initialized"); |
342 | 407 | }
|
343 | 408 | }
|
344 | 409 | catch (Exception ex)
|
345 | 410 | {
|
346 |
| - Debug.LogError($"[VoltUWBAdapter] Disposal error: {ex.Message}"); |
| 411 | + Debug.LogError($"[VoltUWBAdapter] ❌ Disposal error: {ex.Message}"); |
| 412 | + Debug.LogError($"[VoltUWBAdapter] Stack trace: {ex.StackTrace}"); |
347 | 413 | }
|
348 | 414 | }
|
349 | 415 |
|
@@ -589,28 +655,56 @@ private void ConfigureUWBEngine()
|
589 | 655 | {
|
590 | 656 | Debug.Log("[VoltUWBAdapter] 🔧 Configuring UWB CEF Engine for UI instance...");
|
591 | 657 |
|
| 658 | + var detectedPlatform = WebBrowserUtils.GetRunningPlatform(); |
| 659 | + |
592 | 660 | // Create engine configuration (same as SDK but for UI instance)
|
593 | 661 | var engineConfig = ScriptableObject.CreateInstance<EngineConfiguration>();
|
594 | 662 | engineConfig.engineAppName = "UnityWebBrowser.Engine.Cef";
|
595 |
| - engineConfig.engineFiles = new Engine.EnginePlatformFiles[] |
| 663 | + |
| 664 | + var engineFiles = new List<Engine.EnginePlatformFiles>(); |
| 665 | + |
| 666 | + // Windows engine configuration |
| 667 | + engineFiles.Add(new Engine.EnginePlatformFiles() |
596 | 668 | {
|
597 |
| - new Engine.EnginePlatformFiles() |
598 |
| - { |
599 |
| - platform = Platform.Windows64, |
600 |
| - engineBaseAppLocation = "", |
601 |
| - engineRuntimeLocation = "UWB/" |
| 669 | + platform = Platform.Windows64, |
| 670 | + engineBaseAppLocation = "", |
| 671 | + engineRuntimeLocation = "UWB/" |
602 | 672 | #if UNITY_EDITOR
|
603 |
| - , |
604 |
| - engineEditorLocation = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser/[email protected]/Engine~" |
| 673 | + , |
| 674 | + engineEditorLocation = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser/[email protected]/Engine~" |
605 | 675 | #endif
|
606 |
| - } |
607 |
| - }; |
| 676 | + }); |
| 677 | + |
| 678 | + // macOS engine configuration (Intel) |
| 679 | + engineFiles.Add(new Engine.EnginePlatformFiles() |
| 680 | + { |
| 681 | + platform = Platform.MacOS, |
| 682 | + engineBaseAppLocation = "UnityWebBrowser.Engine.Cef.app/Contents/MacOS", |
| 683 | + engineRuntimeLocation = "UWB/" |
| 684 | +#if UNITY_EDITOR |
| 685 | + , |
| 686 | + engineEditorLocation = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser/[email protected]/Engine~" |
| 687 | +#endif |
| 688 | + }); |
| 689 | + |
| 690 | + // macOS engine configuration (ARM64 - Apple Silicon) |
| 691 | + engineFiles.Add(new Engine.EnginePlatformFiles() |
| 692 | + { |
| 693 | + platform = Platform.MacOSArm64, |
| 694 | + engineBaseAppLocation = "UnityWebBrowser.Engine.Cef.app/Contents/MacOS", |
| 695 | + engineRuntimeLocation = "UWB/" |
| 696 | +#if UNITY_EDITOR |
| 697 | + , |
| 698 | + engineEditorLocation = "Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser/dev.voltstro.unitywebbrowser.engine.cef.macos.arm64@2.2.5-130.1.16/Engine~" |
| 699 | +#endif |
| 700 | + }); |
| 701 | + |
| 702 | + engineConfig.engineFiles = engineFiles.ToArray(); |
608 | 703 |
|
609 | 704 | // Assign engine to our UI instance
|
610 | 705 | webBrowserClient.engine = engineConfig;
|
611 | 706 |
|
612 | 707 | Debug.Log("[VoltUWBAdapter] ✅ CEF Engine configured successfully for UI instance");
|
613 |
| - Debug.Log("[VoltUWBAdapter] 🎯 Engine path: Packages/com.immutable.passport/Runtime/ThirdParty/UnityWebBrowser/[email protected]/Engine~"); |
614 | 708 | }
|
615 | 709 | catch (System.Exception ex)
|
616 | 710 | {
|
|
0 commit comments