Skip to content

Commit

Permalink
[MediaVision] Prevent GC of object including unmanaged handle (#6044)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsgwon committed Apr 2, 2024
1 parent b47915f commit d4b397a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static void SetDesignQrOptions(QrConfiguration qrConfig, BarcodeGenerati
InteropBarcode.GenerateSource(EngineConfiguration.GetHandle(config),
message, type, qrMode, qrEcc, qrVersion, source.Handle).
Validate("Failed to generate source");
GC.KeepAlive(config);
}
catch (Exception)
{
Expand Down Expand Up @@ -128,6 +129,8 @@ public static MediaVisionSource GenerateSource(string message, QrConfiguration q
public static MediaVisionSource GenerateSource(string message, QrConfiguration qrConfig,
BarcodeGenerationConfiguration config)
{
BarcodeGenerationConfiguration config_ = null;

if (qrConfig == null)
{
throw new ArgumentNullException(nameof(qrConfig));
Expand All @@ -145,14 +148,18 @@ public static MediaVisionSource GenerateSource(string message, QrConfiguration q
if (qrConfig.DataShape != QrShape.Rectangular || qrConfig.FinderShape != QrShape.Rectangular ||
qrConfig.EmbedImagePath != null)
{
config = new BarcodeGenerationConfiguration();
// Design QR case. The config_ for legacy QR will be null.
config_ = new BarcodeGenerationConfiguration();
}
}

SetDesignQrOptions(qrConfig, config);
SetDesignQrOptions(qrConfig, config ?? config_);

return GenerateSource(config, message, BarcodeType.QR, (int)qrConfig.Mode,
var mediaVisionSource = GenerateSource(config ?? config_, message, BarcodeType.QR, (int)qrConfig.Mode,
(int)qrConfig.ErrorCorrectionLevel, qrConfig.Version);
config_?.Dispose();

return mediaVisionSource;
}

/// <summary>
Expand Down

0 comments on commit d4b397a

Please sign in to comment.