#freezing with CompletableFuture

1 messages · Page 1 of 1 (latest)

fading bane
#

Hi, I'm creating a mod and I was trying to link an event to the reloading of resources, it asked for a CompletableFuture and I did that, but now the game won't stop loading, why does this happen?

@SubscribeEvent
    public static void onResourceReload(RegisterClientReloadListenersEvent event) {
        event.registerReloadListener((pPreparationBarrier, pResourceManager, pPreparationsProfiler, pReloadProfiler, pBackgroundExecutor, pGameExecutor) ->
                CompletableFuture.runAsync(FluidDisplayWidget::clearFluidTextureCache, pGameExecutor)
        );
    }
plucky ridgeBOT
#

<@&987246652869971988> please have a look, thanks.

plucky ridgeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

ding. It seems like you might be experiencing a freezing issue with your CompletableFuture in your mod. Here are a few possible reasons and solutions to help you troubleshoot the problem:

  1. Blocking code: Make sure that you are not blocking the main thread or any other critical threads when using CompletableFuture. Blocking operations can cause the game to freeze. Ensure that any potentially long-running or blocking code is executed in a separate thread or asynchronously.

  2. Deadlock: Check if there is a possibility of a deadlock in your CompletableFuture chain. Deadlocks occur when two or more threads are waiting for each other to release resources, resulting in a freeze. Review your code and ensure that there are no circular dependencies or situations where threads can get stuck waiting indefinitely.

  3. Exception handling: Verify that you have proper exception handling in place for your CompletableFuture chain. Unhandled exceptions can cause the program to freeze without any error messages or indications of what went wrong.

  4. Infinite loop: Check if there is an unintentional infinite loop in your CompletableFuture chain, causing it to never complete and freezing the game. Make sure that all conditions for completing the CompletableFuture are properly handled and tested.

  5. Resource overload: Consider if the resources being loaded by your CompletableFuture are too large or numerous, causing excessive memory usage and slowing down the game's performance. Optimize your resource loading process to minimize memory usage and improve efficiency.

  6. Profiling and debugging: Use profiling tools or debuggers to analyze the performance of your mod and identify any bottlenecks or issues causing freezing. This will help you pinpoint specific areas of improvement and optimize your code accordingly.

Remember to thoroughly test each change you make to ensure it resolves the freezing issue without introducing new problems.