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

error on view3D.dispose() (i now provided my code) #56

Open
VMan-2002 opened this issue Dec 17, 2023 · 12 comments
Open

error on view3D.dispose() (i now provided my code) #56

VMan-2002 opened this issue Dec 17, 2023 · 12 comments

Comments

@VMan-2002
Copy link

Error occurs when trying to dispose a View3D.

Thread 0 (critical error: Null Object Reference):
*    27 : openfl.display3D.Program3D.__deleteShaders() at openfl/display3D/Program3D.hx:597
     26 : openfl.display3D.Program3D.dispose() at openfl/display3D/Program3D.hx:113
     25 : away3d.core.managers.AGALProgram3DCache.destroyProgram() at away3d/core/managers/AGALProgram3DCache.hx:126
     24 : away3d.core.managers.AGALProgram3DCache.dispose() at away3d/core/managers/AGALProgram3DCache.hx:76
     23 : away3d.core.managers.AGALProgram3DCache.onContext3DDisposed() at away3d/core/managers/AGALProgram3DCache.hx:65
     22 : openfl.events.EventDispatcher.__dispatchEvent() at openfl/events/EventDispatcher.hx:402
     21 : openfl.events.EventDispatcher.dispatchEvent() at openfl/events/EventDispatcher.hx:246
     20 : away3d.core.managers.Stage3DProxy.freeContext3D() at away3d/core/managers/Stage3DProxy.hx:557
     19 : away3d.core.managers.Stage3DProxy.dispose() at away3d/core/managers/Stage3DProxy.hx:177
     18 : away3d.containers.View3D.dispose() at away3d/containers/View3D.hx:937
     17 : object3d.VeView3D.destroy() at object3d/VeView3D.hx:66
     16 : flixel.group.FlxTypedGroup.destroy() at flixel/group/FlxGroup.hx:154
     15 : flixel.FlxState.destroy() at flixel/FlxState.hx:165
     14 : flixel.FlxGame.switchState() at flixel/FlxGame.hx:624
     13 : flixel.FlxGame.update() at flixel/FlxGame.hx:724
     12 : flixel.FlxGame.step() at flixel/FlxGame.hx:677
     11 : flixel.FlxGame.onEnterFrame() at flixel/FlxGame.hx:545
     10 : openfl.events.EventDispatcher.__dispatchEvent() at openfl/events/EventDispatcher.hx:402
      9 : openfl.display.DisplayObject.__dispatch() at openfl/display/DisplayObject.hx:1399
      8 : openfl.display.Stage.__broadcastEvent() at openfl/display/Stage.hx:1181
      7 : openfl.display.Stage.__onLimeRender() at openfl/display/Stage.hx:2046
      6 : lime.app._Event_lime_graphics_RenderContext_Void.dispatch() at lime/_internal/macros/EventMacro.hx:91
      5 : lime._internal.backend.native.NativeApplication.handleRenderEvent() at lime/_internal/backend/native/NativeApplication.hx:371
      4 : lime._internal.backend.native.NativeApplication.exec() at lime/_internal/backend/native/NativeApplication.hx:146
      3 : lime.app.Application.exec() at lime/app/Application.hx:150
      2 : ApplicationMain.create() at ApplicationMain.hx:135
      1 : ApplicationMain.main() at ApplicationMain.hx:26
      0 : hxcpp.__hxcpp_main() at ?:1

Original issue (possibly outdated) in 2015 by ramsestom from away3d/away3d-core-openfl

I have an ObjectContainer3D OC1 that contains 2 other ObjectContainer3D OC2 and OC3 (containing each one a mesh).
If I add only OC1 as child to my view3D, calling the view3D.dispose() function make the program to crash with this error:

Null Object Reference
Called from openfl._legacy.display.Stage.__pollTimers (openfl/_legacy/display/Stage.hx line 1084)
Called from openfl._legacy.display.Stage.__checkRender (openfl/_legacy/display/Stage.hx line 351)
Called from openfl._legacy.display.Stage.__render (openfl/_legacy/display/Stage.hx line 1103)
Called from openfl._legacy.display.DisplayObjectContainer.__broadcast (openfl/_legacy/display/DisplayObjectContainer.hx line 286)
Called from openfl._legacy.display.DisplayObject.__broadcast (openfl/_legacy/display/DisplayObject.hx line 161)
Called from openfl._legacy.display.DisplayObject.__dispatchEvent (openfl/_legacy/display/DisplayObject.hx line 182)
Called from openfl._legacy.events.EventDispatcher.dispatchEvent (openfl/_legacy/events/EventDispatcher.hx line 98)
Called from flixel.FlxGame.onEnterFrame (flixel/FlxGame.hx line 523)
Called from flixel.FlxGame.step (flixel/FlxGame.hx line 681)
Called from flixel.FlxGame.update (flixel/FlxGame.hx line 701)
Called from flixel.FlxGame.switchState (flixel/FlxGame.hx line 608)
Called from gui.states.PlayState3D.destroy (gui/states/PlayState3D.hx line 289)
Called from away3d.containers.View3D.dispose (away3d/containers/View3D.hx line 1003)
Called from away3d.core.managers.Stage3DProxy.dispose (away3d/core/managers/Stage3DProxy.hx line 151)
Called from away3d.core.managers.Stage3DProxy.freeContext3D (away3d/core/managers/Stage3DProxy.hx line 492)
Called from openfl._legacy.events.EventDispatcher.dispatchEvent (openfl/_legacy/events/EventDispatcher.hx line 98)
Called from away3d.core.managers.AGALProgram3DCache.onContext3DDisposed (away3d/core/managers/AGALProgram3DCache.hx line 58)
Called from away3d.core.managers.AGALProgram3DCache.dispose (away3d/core/managers/AGALProgram3DCache.hx line 68)
Called from away3d.core.managers.AGALProgram3DCache.destroyProgram (away3d/core/managers/AGALProgram3DCache.hx line 115)
Called from openfl.display3D.Program3D.dispose (openfl/display3D/Program3D.hx line 25)
Called from openfl.display3D.Context3D.__deleteProgram (openfl/display3D/Context3D.hx line 229)

Now, If my ObjectContainer3D OC1 only contains 1 Mesh (instead of OC2 and OC3), there is no error. view3D.dispose() succed. The same thing if I I only put OC2 (with 1 mesh) as child of OC1 (so whithout OC3) and then put OC1 as single child of view3D (everything is fine in that case). The issue only appear if I have in my view3D an ObjectContainer3D with more than 1 child in it...

@VMan-2002 VMan-2002 changed the title issue with view3D.dispose() error on view3D.dispose() Dec 17, 2023
@VMan-2002
Copy link
Author

i feel this is a very important issue

@VMan-2002
Copy link
Author

ok i provide my code, has HaxeFlixel use
object3d/VeView3D.hx https://pastebin.com/0m7HdtvH
states/Test3DState.hx https://pastebin.com/Szkx4zWD

@VMan-2002 VMan-2002 changed the title error on view3D.dispose() error on view3D.dispose() (i now provided my code) Jan 12, 2024
@VMan-2002
Copy link
Author

an easily testable project: https://github.com/doggy-dentures/3dsenpai/tree/main
to reproduce crash: just go in (press play) and out (press esc) repeatedly you should get it in at most 2 or 3 cycles

@Dimensionscape
Copy link
Member

You copy pasted a decade old issue verbatim without providing a lot of information about your actual problem.

All of the libraries have changed drastically.

Calling dispose is supposed to clean things up. A null reference occurs when you try to use a reference that doesn't point to anything. If this is happening, somewhere in your code, it is trying to access something that is now null after dispose is called. It could be an away3d issue or it might be openfl, or flixel, or your own code. Its hard to tell without a minimal reproducible example. Maybe these libraries aren't playing nice together.

I couldn't reproduce the issue on my own. I suspect its not necessarily an away 3d problem. Come back with an easily reproducible, minimal example and create a better issue report. The burden to prove there is a bug is on users. We don't have time to investigate everyone's code when the user themselves haven't put in the minimal required effort to help us debug.

@Dimensionscape Dimensionscape closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
@VMan-2002
Copy link
Author

i copied the code into a minimal project, and i have now uploaded it at https://github.com/VMan-2002/AwayViewBug
this example doesn't showcase the bug. i dont know why. i dont understand. i dont know what the difference is between the code existing in X project vs Y (AwayViewBug) project, it just works in Y and causes an error in X. :(

@Dimensionscape
Copy link
Member

The problem exists outside of away3d and in the actual project then I'm afraid. The callstack will tell you where to look.

@VMan-2002
Copy link
Author

ok i discovered something: the bug depends on the -debug flag; the error occurs on both projects X and Y with -debug and occurs on only project X without -debug. i hope this info helps

@Dimensionscape
Copy link
Member

I will take a look when I get a chance this week.

@Dimensionscape
Copy link
Member

Show me the callstack please. @VMan-2002

@VMan-2002
Copy link
Author

Show me the callstack please. @VMan-2002

Called from ApplicationMain::main ApplicationMain.hx line 26
Called from ApplicationMain::create ApplicationMain.hx line 137
Called from openfl.display.Application::exec openfl/display/Application.hx line 130
Called from lime.app.Application::exec lime/app/Application.hx line 150
Called from lime._internal.backend.native.NativeApplication::exec lime/_internal/backend/native/NativeApplication.hx line 146
Called from lime._internal.backend.native.NativeApplication::handleRenderEvent lime/_internal/backend/native/NativeApplication.hx line 375
Called from lime.app._Event_lime_graphics_RenderContext_Void::dispatch lime/_internal/macros/EventMacro.hx line 91
Called from openfl.display.Stage::__onLimeRender openfl/display/Stage.hx line 2177
Called from openfl.display.Stage::__broadcastEvent openfl/display/Stage.hx line 1187
Called from openfl.display.DisplayObject::__dispatch openfl/display/DisplayObject.hx line 1398
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 426
Called from flixel.FlxGame::onEnterFrame flixel/FlxGame.hx line 545
Called from flixel.FlxGame::step flixel/FlxGame.hx line 677
Called from flixel.FlxGame::update flixel/FlxGame.hx line 724
Called from flixel.FlxGame::switchState flixel/FlxGame.hx line 624
Called from flixel.FlxState::destroy flixel/FlxState.hx line 165
Called from flixel.group.FlxTypedGroup::destroy flixel/group/FlxGroup.hx line 154
Called from object3d.VeView3D::destroy object3d/VeView3D.hx line 133
Called from away3d.containers.View3D::dispose away3d/containers/View3D.hx line 937
Called from away3d.core.managers.Stage3DProxy::dispose away3d/core/managers/Stage3DProxy.hx line 177
Called from away3d.core.managers.Stage3DProxy::freeContext3D away3d/core/managers/Stage3DProxy.hx line 557
Called from openfl.events.EventDispatcher::dispatchEvent openfl/events/EventDispatcher.hx line 250
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 426
Called from away3d.core.managers.AGALProgram3DCache::onContext3DDisposed away3d/core/managers/AGALProgram3DCache.hx line 65
Called from away3d.core.managers.AGALProgram3DCache::dispose away3d/core/managers/AGALProgram3DCache.hx line 76
Called from away3d.core.managers.AGALProgram3DCache::destroyProgram away3d/core/managers/AGALProgram3DCache.hx line 126
Called from openfl.display3D.Program3D::dispose openfl/display3D/Program3D.hx line 113
Called from openfl.display3D.Program3D::__deleteShaders openfl/display3D/Program3D.hx line 597
Critical Error: Uncatchable Throw: Null Object Reference```

@Dimensionscape
Copy link
Member

Dimensionscape commented Apr 11, 2024

Okay it looks like the gl context may already be null.

This may be an openfl issue.

I'm on my phone right now so I can't make the change and send you a branch, you'll have to try this yourself.

go to https://github.com/openfl/openfl/blob/c7861adaca97dff8697b334162a04a60e5d7090b/src/openfl/display3D/Program3D.hx#L586 in your openfl version or branch and replace the function as follows:

@:noCompletion private function __deleteShaders():Void
	{
		var gl = __context.gl;

		if (__glProgram != null)
		{
			__glProgram = null;
		}

		if (__glVertexShader != null)
		{

			if(gl != null) gl.deleteShader(__glVertexShader);
			__glVertexShader = null;
		}

		if (__glFragmentShader != null)
		{
			if(gl != null) gl.deleteShader(__glFragmentShader);
			__glFragmentShader = null;
		}
	}

let me know if that solves your problem.

@Dimensionscape
Copy link
Member

Feel free to join our discord if you want realtime support and feedback from the community. https://discord.gg/gzTnHZybr7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants