Skip to content

Commit

Permalink
Prevented possible collection of the callback delegates and the resul…
Browse files Browse the repository at this point in the history
…ting crash
  • Loading branch information
DarthAffe committed Mar 19, 2024
1 parent 631c8ca commit e2015e7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions StableDiffusion.NET/StableDiffusionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public sealed unsafe class StableDiffusionModel : IDisposable
{
#region Properties & Fields

// ReSharper disable NotAccessedField.Local - They are important, the delegate can be collected if it's not stored!
private static readonly Native.sd_log_cb_t LOG_CALLBACK;
private static readonly Native.sd_progress_cb_t PROGRESS_CALLBACK;
// ReSharper restore NotAccessedField.Local

private bool _disposed;

private readonly string _modelPath;
Expand All @@ -29,8 +34,8 @@ public sealed unsafe class StableDiffusionModel : IDisposable

static StableDiffusionModel()
{
Native.sd_set_log_callback(OnNativeLog, null);
Native.sd_set_progress_callback(OnNativeProgress, null);
Native.sd_set_log_callback(LOG_CALLBACK = OnNativeLog, null);
Native.sd_set_progress_callback(PROGRESS_CALLBACK = OnNativeProgress, null);
}

public StableDiffusionModel(string modelPath, ModelParameter parameter, UpscalerModelParameter? upscalerParameter = null)
Expand Down

0 comments on commit e2015e7

Please sign in to comment.