-2

Well, I have little knowledge about OpenGL. Please help me understand why the error show up and what could be the possible ways to solve the error.

Here is my code:

from ursina import *
import pyvista as pv
from pyvista import examples

# Starting an ursina app
app = Ursina()
# Define a parent entity of ursina
prnt = Entity()

# Defne a button entity which calls the method pyvista_display on click
Button("click", parent=prnt, scale=1, on_click=lambda: pyvista_display())


def pyvista_display():  # Method to display a simple pyvista mesh
    # Load an interesting example of geometry
    mesh = examples.load_random_hills()

    # Establish geometry within a pv.Plotter()
    p = pv.Plotter()
    # Add mesh to the plotter
    p.add_mesh(mesh, color=True)
    # Show the plotter
    p.show()

    p.close()


# Run ursina app
app.run()

Description of the module:

  • Module imports ursina, pyvista and pyvista example package
  • I run an ursina application. In the application, only a functional button is there with label "click"
  • While I click the button, the function pyvista_display() is called.
  • Function pyvista_display() simple opens a pyvista window and display a mesh from inbuilt pyvista example package (which I have imported above)

Error Showing Moment: Till now the code is running perfectly fine. I click the "click" button and the pyvista window shows up and display the simple example mesh. Problem arises when I close the pyvista window. When I close the pyvista window, below error message is showing on my terminal. And the message is showing in an infinite loop like we are printing something in a loop without limit.

Error

:display:gsg:glgsg(error): GL error 0x502 : invalid operation

Error message meaning from ChatGPT

The error message :display:gsg:glgsg(error): GL error 0x502 : invalid operation is an OpenGL error message that indicates an invalid operation was attempted within an OpenGL context. The error code 0x502 corresponds to the OpenGL constant GL_INVALID_OPERATION.

Expectation:

  • Expected to close the pyvista window properly and continue to run the application without any error.
  • Like after I close the pyvista window, ursina window with "click" button still continue to run. And the pyvista window again shows up when I again click the "click" window

Request: As I have already mentioned above that I have very little knowledge about OpenGL, if you identify the error and solve me the problem, it would be a blessing for me. Or if you provide me an alternative way to reach the expectation, I am ready to listen to your suggestions.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Sonarjit
  • 5
  • 2

1 Answers1

-1

Alternative Solution with multi-threading

I was expecting to show the pyvista mesh in ursina window itself. I cannot accomplish the exact expectation but I come up with an alternative solution.

The alternative solution executes by creative separate thread of pyvista window. When I click the "click" button in ursina window, it triggers the start_pyvista_thread() method. This method creates pyvista thread targeting the pyvista_display() method when it starts. pyvista_display() contains the necessary code to display the pyvista mesh. Thus, the code creates separate window of pyvista and display the pyvista mesh.

That's it! Simple execution using threading concept.

from ursina import *
import threading
import pyvista as pv
from pyvista import examples

# Define the Ursina app
app = Ursina()

# Define a parent entity for Ursina
prnt = Entity()

# Method to display a simple PyVista mesh


def pyvista_display():
    # Load an interesting example of geometry
    mesh = examples.load_random_hills()

    # Establish geometry within a pv.Plotter()
    p = pv.Plotter()
    # Add mesh to the plotter
    p.add_mesh(mesh, color=True)
    # Show the plotter
    p.show()

# Method to start a new PyVista thread
def start_pyvista_thread():
    # Create a thread for PyVista rendering
    pyvista_thread = threading.Thread(target=pyvista_display)
    pyvista_thread.start()


# Define a button entity that starts a new PyVista thread on click
Button("click", parent=prnt, scale=1, on_click=start_pyvista_thread)

# Run the Ursina app
app.run()

Sonarjit
  • 5
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 19 '23 at 16:23