Finding a function, general advice

I am working on issue 1047 and have got a test case working that shows the bug. I am in the process of tracking down where in the code the bug occurs. However, I have hit a roadblock in that I am unable to find the function loadSync in the code.
It is used at line 288 in Loader.py to load a model. What I normally have done to continue to trace through code is one of the following

  1. Step into it using the debugger (Doesn’t work, just steps over it)
  2. Use the functions of the IDE I am using to find it
  3. As a last resort, do a general search

None of these are turning up the function. My guess is that it is jumping into the C++ code at that point, but I can’t find it. Any ideas appreciated.

Equivalent to C++ load_model(framework.get_models(), "panda")

Located here. https://docs.panda3d.org/1.10/cpp/reference/panda3d.core.ModelPool#modelpool
https://docs.panda3d.org/1.10/cpp/reference/panda3d.core.Loader?highlight=loader#_CPPv46Loader

In general, the search functionality of the manual/API seems to be pretty effective. A quick search for “loadSync” quite quickly turned up its presence in the “Loader” class.

So if you’re struggling to find a function or method, I’d suggest turning to the manual’s search bar!

Thanks Taumaturge. That gives me the Loader.py class, but there is no LoadSync there. serega-kkz load_model got me on the right track. However, how does LoadSync in python lead you to load_model in C++?

It is there, I believe–but as “load_sync” (i.e. in snake-case, not camel-case).

See this direct link to the function’s API-entry:
https://docs.panda3d.org/1.10/cpp/reference/panda3d.core.Loader?#_CPPv4NK6Loader9load_syncERK8FilenameRK13LoaderOptions
(You may have to scroll up just a little–I know that on my machine, at least, those direct links jump to a point such that the title is hidden behind the menu-bar.)

In general, and if I’m not much mistaken, Panda’s methods and functions are created in snake-case first, and camel-case as a convenience after. (And possibly for Python only; I’m not sure.) In some cases, the API may not show the camel-case versions. (Or only shows them in the Python API, as is the case here.)

Thus, if you don’t find the camel-case version, it’s worth looking for the presence of the snake-case version.

Note that the search function seems to direct you to the right module anyway–you may just have to manually search within the resultant page.

loader = Loader.get_global_ptr()
model = NodePath(loader.load_sync("panda.egg"))
model.reparentTo(render)

It happens like this.

So, this can seem a bit confusing at first, but:

  • Methods in the C++ code are defined as load_sync(), and camelCase aliases are automatically generated for compatibility reasons. So if you are searching the source code (which is the best way to find something; I use ripgrep myself)
  • Loader.py and the C++ Loader class are two distinct things. The former uses the latter under the hood. The latter is defined in panda/src/pgraph/loader.{h,cxx,I} and is what contains load_sync().

Thanks rdb, that cleared things up completely.