Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FontManager.RenderBitmap() access violation exception #1692

Closed
NicusorN5 opened this issue Jun 13, 2023 · 6 comments
Closed

FontManager.RenderBitmap() access violation exception #1692

NicusorN5 opened this issue Jun 13, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@NicusorN5
Copy link
Contributor

NicusorN5 commented Jun 13, 2023

Release Type: Github

Version: Master git branch

Platform(s): Windows

Describe the bug
Creating and loading a new project results in Stride crashing at startup.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new project for example, "AnimatedModel" in my example.
  2. Wait for the scene to load
  3. Crash at line 155
var renderingMode = character.AntiAlias == FontAntiAliasMode.Aliased ? RenderMode.Mono : RenderMode.Normal;

inside FontManager.cs

Expected behavior
I expected the scene to load sucessfully...

Log and callstacks

An unhandled exception of type 'System.AccessViolationException' occurred in SharpFont.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Callstack

 	[Managed to Native Transition]	
 	SharpFont.dll!SharpFont.GlyphSlot.RenderGlyph(SharpFont.RenderMode mode)	Unknown
	Stride.Graphics.dll!Stride.Graphics.Font.FontManager.RenderBitmap(Stride.Graphics.Font.CharacterSpecification character, SharpFont.Face fontFace) Line 155	C#
 	Stride.Graphics.dll!Stride.Graphics.Font.FontManager.BuildBitmapThread() Line 320	C#
 	Stride.Core.dll!Stride.Core.Diagnostics.SafeAction.Wrap.AnonymousMethod__0() Line 21	C#
 	System.Private.CoreLib.dll!System.Threading.Thread.StartHelper.Callback(object state)	Unknown
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	System.Private.CoreLib.dll!System.Threading.Thread.StartCallback()	Unknown

Additional context
In the debugger, FontFace.GlyphCount throws a overflow error. Same with fontFace.StyleFlags


Update 1: I have found out that this issue doesn't exist on the lastest release 4.1.0.1838

@NicusorN5 NicusorN5 added the bug Something isn't working label Jun 13, 2023
@NicusorN5 NicusorN5 changed the title FontManager.RenderBitmap access violation exception FontManager.RenderBitmap() access violation exception Jun 13, 2023
@NicusorN5
Copy link
Contributor Author

NicusorN5 commented Jul 21, 2023

With the latest master commits, this also seems to happen randomly when modifying UI pages. More time needed to search how and why this is happening is required.

Current stacktrace (2nd, I lost the first)

   at System.IntPtr.op_Explicit(IntPtr value)
   at SharpFont.FTVector26Dot6.get_X()
   at Stride.Graphics.Font.FontManager.GenerateCharacterGlyph(CharacterSpecification character, Boolean renderBitmap) in D:\Dev\Stride\sources\engine\Stride.Graphics\Font\FontManager.cs:line 144
   at Stride.Graphics.Font.FontManager.GenerateBitmap(CharacterSpecification characterSpecification, Boolean synchronously) in D:\Dev\Stride\sources\engine\Stride.Graphics\Font\FontManager.cs:line 101
   at Stride.Graphics.Font.RuntimeRasterizedSpriteFont.GetGlyph(CommandList commandList, Char character, Vector2& fontSize, Boolean uploadGpuResources, Vector2& fixScaling) in D:\Dev\Stride\sources\engine\Stride.Graphics\Font\RuntimeRasterizedSpriteFont.cs:line 113
   at Stride.Graphics.SpriteFont.ForGlyph[T](CommandList commandList, StringProxy& text, Vector2& fontSize, GlyphAction`1 action, T& parameters, Int32 forStart, Int32 forEnd, Boolean updateGpuResources, Single startX, Single startY) in D:\Dev\Stride\sources\engine\Stride.Graphics\SpriteFont.cs:line 575
   at Stride.Graphics.SpriteFont.ForEachGlyph[T](CommandList commandList, StringProxy& text, Vector2& requestedFontSize, GlyphAction`1 action, T& parameters, TextAlignment scanOrder, Boolean updateGpuResources, Nullable`1 textBoxSize) in D:\Dev\Stride\sources\engine\Stride.Graphics\SpriteFont.cs:line 512
   at Stride.Graphics.SpriteFont.InternalUIDraw(CommandList commandList, StringProxy& text, InternalUIDrawCommand& drawCommand) in D:\Dev\Stride\sources\engine\Stride.Graphics\SpriteFont.cs:line 258
   at Stride.Graphics.UIBatch.DrawString(SpriteFont font, String text, InternalUIDrawCommand& drawCommand) in D:\Dev\Stride\sources\engine\Stride.Graphics\UIBatch.cs:line 480
   at Stride.UI.Renderers.DefaultTextBlockRenderer.RenderColor(UIElement element, UIRenderingContext context) in D:\Dev\Stride\sources\engine\Stride.UI\Renderers\DefaultTextBlockRenderer.cs:line 50
   at Stride.Rendering.UI.UIRenderFeature.RecursiveDrawWithClipping(RenderDrawContext context, UIElement element, Matrix& worldViewProj, SamplerState samplerState) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 313
   at Stride.Rendering.UI.UIRenderFeature.RecursiveDrawWithClipping(RenderDrawContext context, UIElement element, Matrix& worldViewProj, SamplerState samplerState) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 317
   at Stride.Rendering.UI.UIRenderFeature.RecursiveDrawWithClipping(RenderDrawContext context, UIElement element, Matrix& worldViewProj, SamplerState samplerState) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 317
   at Stride.Rendering.UI.UIRenderFeature.DrawInternal(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, Int32 startIndex, Int32 endIndex) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 269
   at Stride.Rendering.UI.UIRenderFeature.Draw(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, Int32 startIndex, Int32 endIndex) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 86
   at Stride.Rendering.RenderSystem.Draw(RenderDrawContext renderDrawContext, RenderView renderView, RenderStage renderStage) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\RenderSystem.cs:line 341
   at Stride.Rendering.Compositing.ForwardRenderer.DrawView(RenderContext context, RenderDrawContext drawContext, Int32 eyeIndex, Int32 eyeCount) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\ForwardRenderer.cs:line 557
   at Stride.Rendering.Compositing.ForwardRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\ForwardRenderer.cs:line 750
   at Stride.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\Compositing\SceneRendererBase.cs:line 39
   at Stride.Rendering.Compositing.SceneCameraRenderer.DrawInner(RenderDrawContext renderContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\SceneCameraRenderer.cs:line 105
   at Stride.Rendering.Compositing.EditorTopLevelCompositor.DrawInner(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\EditorTopLevelCompositor.cs:line 61
   at Stride.Rendering.Compositing.SceneCameraRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\SceneCameraRenderer.cs:line 70
   at Stride.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\Compositing\SceneRendererBase.cs:line 39
   at Stride.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\GraphicsCompositor.cs:line 184
   at Stride.Rendering.RendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\RendererBase.cs:line 49
   at Stride.Engine.SceneSystem.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Engine\Engine\SceneSystem.cs:line 234
   at Stride.Games.GameSystemCollection.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Games\GameSystemCollection.cs:line 132
   at Stride.Games.GameBase.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Games\GameBase.cs:line 795
   at Stride.Editor.EditorGame.Game.EditorServiceGame.Draw(GameTime gameTime) in D:\Dev\Stride\sources\editor\Stride.Editor\EditorGame\Game\EditorServiceGame.cs:line 214

3rd consecutive stack trace

 at Stride.Graphics.BatchBase`1.CheckEndHasBeenCalled(String functionName) in D:\Dev\Stride\sources\engine\Stride.Graphics\BatchBase.cs:line 267
 at Stride.Graphics.BatchBase`1.Begin(GraphicsContext graphicsContext, EffectInstance effect, SpriteSortMode sessionSortMode, Nullable`1 sessionBlendState, SamplerState sessionSamplerState, Nullable`1 sessionDepthStencilState, Nullable`1 sessionRasterizerState, Int32 stencilValue) in D:\Dev\Stride\sources\engine\Stride.Graphics\BatchBase.cs:line 173
 at Stride.Graphics.UIBatch.Begin(GraphicsContext graphicsContext, Matrix& viewProjection, Nullable`1 blendState, SamplerState samplerState, Nullable`1 rasterizerState, Nullable`1 depthStencilState, Int32 stencilValue) in D:\Dev\Stride\sources\engine\Stride.Graphics\UIBatch.cs:line 197
 at Stride.Rendering.UI.UIRenderFeature.DrawInternal(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, Int32 startIndex, Int32 endIndex) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 266
 at Stride.Rendering.UI.UIRenderFeature.Draw(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, Int32 startIndex, Int32 endIndex) in D:\Dev\Stride\sources\engine\Stride.UI\Rendering\UI\UIRenderFeature.cs:line 86
 at Stride.Rendering.RenderSystem.Draw(RenderDrawContext renderDrawContext, RenderView renderView, RenderStage renderStage) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\RenderSystem.cs:line 341
 at Stride.Rendering.Compositing.ForwardRenderer.DrawView(RenderContext context, RenderDrawContext drawContext, Int32 eyeIndex, Int32 eyeCount) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\ForwardRenderer.cs:line 557
 at Stride.Rendering.Compositing.ForwardRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\ForwardRenderer.cs:line 750
 at Stride.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\Compositing\SceneRendererBase.cs:line 39
 at Stride.Rendering.Compositing.SceneCameraRenderer.DrawInner(RenderDrawContext renderContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\SceneCameraRenderer.cs:line 105
 at Stride.Rendering.Compositing.EditorTopLevelCompositor.DrawInner(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\EditorTopLevelCompositor.cs:line 61
 at Stride.Rendering.Compositing.SceneCameraRenderer.DrawCore(RenderContext context, RenderDrawContext drawContext) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\SceneCameraRenderer.cs:line 70
 at Stride.Rendering.Compositing.SceneRendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\Compositing\SceneRendererBase.cs:line 39
 at Stride.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Engine\Rendering\Compositing\GraphicsCompositor.cs:line 184
 at Stride.Rendering.RendererBase.Draw(RenderDrawContext context) in D:\Dev\Stride\sources\engine\Stride.Rendering\Rendering\RendererBase.cs:line 49
 at Stride.Engine.SceneSystem.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Engine\Engine\SceneSystem.cs:line 234
 at Stride.Games.GameSystemCollection.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Games\GameSystemCollection.cs:line 132
 at Stride.Games.GameBase.Draw(GameTime gameTime) in D:\Dev\Stride\sources\engine\Stride.Games\GameBase.cs:line 795
 at Stride.Editor.EditorGame.Game.EditorServiceGame.Draw(GameTime gameTime) in D:\Dev\Stride\sources\editor\Stride.Editor\EditorGame\Game\EditorServiceGame.cs:line 214

Next shown errors are the same as the 3rd.

@IXLLEGACYIXL
Copy link
Collaborator

IXLLEGACYIXL commented Sep 12, 2023

can you try in the fontmanager using this as line 144 and try to replicate it?
character.Glyph.XAdvance = fontFace.Glyph.Advance.X.ToSingle() * 64f;

using this stops stride from crashing when adding a UI page to a camera ( no idea if the font crashs then.. but stride doesnt anymore )

@NicusorN5
Copy link
Contributor Author

No effect. Your suggestion doesn't even make sense, atleast in my case, since fontFace.Glyph.Advance.X.ToSingle() is 0.

@Doprez
Copy link
Contributor

Doprez commented Sep 19, 2023

Adding info here as I just faced the same issue. It seems to be specifically with BuildBitmapThread() in the FontManager.cs class if I remove the call to RenderBitmap(character, fontFace); the crashing stopped but the runtime rasterized fonts no longer worked.

It also stopped crashing all together so I can no longer reproduce for some reason..

@NicusorN5
Copy link
Contributor Author

NicusorN5 commented Sep 19, 2023

It's most likely a non deterministic bug. At least I don't understand the circumstances needed to exactly reproduce this issue.
Also check #1750

Behaviour may be different from each commit. YMMV.

@NicusorN5
Copy link
Contributor Author

Fixed by #1999 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants