Bug with CreateShader

Just starting out? Need help? Post your questions and find answers here.
User avatar
inn3r100p
New User
New User
Posts: 8
Joined: Sun Oct 27, 2024 8:18 am
Contact:

Bug with CreateShader

Post by inn3r100p »

Hello!
Another bug with Engine, fails on CreateShaderMaterial and hangs on CloseScreen when we create custom (not predefined) shader
here is minimal example to reproduce:

Code: Select all

EnableExplicit

Define shaderFile.i

shaderFile = CreateFile( #PB_Any, "test.vs", #PB_File_SharedRead | #PB_File_NoBuffering | #PB_UTF8 )
WriteStringN( shaderFile, "void main( ) { }", #PB_UTF8 )
CloseFile( shaderFile )

shaderFile = CreateFile( #PB_Any, "test.fs", #PB_File_SharedRead | #PB_File_NoBuffering | #PB_UTF8 )
WriteStringN( shaderFile, "void main( ) { }", #PB_UTF8 )
CloseFile( shaderFile )

Define screenWindow.i = OpenWindow( #PB_Any, 0, 0, 800, 600, "" )

InitEngine3D( #PB_Engine3D_DebugLog )

InitSprite( )
OpenWindowedScreen( WindowID( screenWindow ), 0, 0, 800, 600, #False, 0, 0, #PB_Screen_WaitSynchronization )

Define mainCamera.i = CreateCamera( #PB_Any, 0, 0, 100, 100 )
CameraBackColor( mainCamera, $DEC4B0 )
MoveCamera( mainCamera, 0.0, 5.0, -7.0, #PB_Absolute )
CameraLookAt( mainCamera, 0.0, 0.0, 0.0 )

Define mainLight.i = CreateLight( #PB_Any, $DEC4B0, 10.0, 10.0, 10.0, #PB_Light_Directional )
LightLookAt( mainLight, 0.0, 0.0, 0.0 )

Define testShader.i = CreateShader( 0, "test.vs", "test.fs" )
Debug "testShader: " + Str( testShader )
Define testMaterial.i = CreateShaderMaterial( #PB_Any, testShader ); <<-- FAILED
If IsMaterial( testMaterial ) = 0
	Debug "CreateShaderMaterial failed!"
	testMaterial = CreateMaterial( #PB_Any, #Null, $0000FF )
EndIf
Define testMesh.i     = CreateCube( #PB_Any, 1.0 )
Define testEntity.i   = CreateEntity( #PB_Any, MeshID( testMesh ), MaterialID( testMaterial ) )

Repeat
	Define winEvent = WindowEvent( )
	If winEvent = #PB_Event_CloseWindow
		Break
	ElseIf winEvent <> 0
		Continue
	EndIf
	RenderWorld( )
	FlipBuffers( )
Forever

CloseScreen( ); <<-- HANGS HERE
CloseWindow( screenWindow )
End


// Moved from "Bugs - 3D Engine" to "Coding Questions" (Kiffi)
miso
Enthusiast
Enthusiast
Posts: 491
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Bug with CreateShader

Post by miso »

Createshader needs the vertex and fragment shader code as string, and not a filename.
User avatar
inn3r100p
New User
New User
Posts: 8
Joined: Sun Oct 27, 2024 8:18 am
Contact:

Re: Bug with CreateShader

Post by inn3r100p »

miso wrote: Mon Dec 02, 2024 5:19 pm Createshader needs the vertex and fragment shader code as string, and not a filename.
Ouch!) thanks for the clarification, but it does'nt matter, CreateShaderMaterial fails anyway and we also have freeze on CloseScreen :(
User avatar
inn3r100p
New User
New User
Posts: 8
Joined: Sun Oct 27, 2024 8:18 am
Contact:

Re: Bug with CreateShader

Post by inn3r100p »

Oh, checking it again and find that CreateShader with ShaderID > 0 works.
Post Reply