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

Fix crashes #232

Merged
merged 1 commit into from
Sep 13, 2024
Merged

Fix crashes #232

merged 1 commit into from
Sep 13, 2024

Conversation

kimkulling
Copy link
Owner

@kimkulling kimkulling commented Sep 12, 2024

  • Fix crashes in the samples
  • Editor works again

Summary by CodeRabbit

  • New Features

    • Introduced a file open dialog in the application, allowing users to dynamically import assets during runtime.
    • Added new enumerations for window management, enhancing clarity and type safety for window configurations.
  • Bug Fixes

    • Improved key handling logic to prevent updates when an unknown key is detected.
  • Refactor

    • Updated window initialization parameters from boolean flags to enumerated types for better readability and maintainability.

Copy link

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve updates to various application components, primarily focusing on the initWindow method across multiple classes. The modifications replace boolean parameters for window mode and type with enumerated types, enhancing clarity and type safety. Additionally, a new asset import feature is introduced in the OsreEdApp class, allowing users to dynamically load assets during runtime. The overall structure of the application is refined to improve readability and maintainability.

Changes

Files Change Summary
samples/01_ModelLoading/ModelLoading.cpp Modified initWindow parameters from boolean to WindowMode and WindowType enums.
samples/03_Instancing/Instancing.cpp Modified initWindow parameters from boolean to WindowMode and WindowType enums.
samples/04_terrain/TerrainRendering.cpp Modified initWindow parameters from boolean to WindowMode and WindowType enums.
src/Editor/src/OsreEdApp.cpp Added functionality for asset import via a file open dialog triggered by the 'O' key; updated key handling logic.
src/Editor/src/main.cpp Updated initWindow parameters for window mode and type; removed asset loading dialog functionality, streamlining the main application loop.
src/Engine/App/AppBase.cpp Modified initWindow parameters from boolean to WindowMode and WindowType enums; updated logic for setting window properties.
src/Engine/App/AppBase.h Added WindowMode and WindowType enumerations; modified initWindow method signature to use these enums instead of boolean flags.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OsreEdApp
    participant PlatformOperations

    User->>OsreEdApp: Press 'O' key
    OsreEdApp->>PlatformOperations: Trigger file open dialog
    PlatformOperations-->>OsreEdApp: Return selected file URI
    OsreEdApp->>OsreEdApp: Validate URI
    OsreEdApp->>OsreEdApp: Load asset
Loading

🐇 "In code we change, with hops and bounds,
Enumerations leap, where clarity is found.
A dialog for assets, now a joyful dance,
With every key pressed, we take a chance.
From boolean to enums, our paths align,
In the world of code, all things combine!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
src/Editor/src/OsreEdApp.cpp (1)

157-163: Approve the new asset import feature with suggestions for improvement.

The new asset import feature looks good and adds a valuable functionality to the application. The use of the file open dialog and the loadAsset method to handle the asset import process is a clean and effective approach.

However, consider the following suggestions for improvement:

  1. Add error handling for the asset import process to gracefully handle any potential errors or exceptions that may occur during the import.
  2. Consider moving the asset import logic to a separate method for better code organization and readability. This will help keep the onUpdate method focused on its primary responsibility of updating the application state every frame.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b83340 and e4c3a76.

Files selected for processing (8)
  • samples/00_HelloWorld/HelloWorld.cpp (1 hunks)
  • samples/01_ModelLoading/ModelLoading.cpp (1 hunks)
  • samples/03_Instancing/Instancing.cpp (1 hunks)
  • samples/04_terrain/TerrainRendering.cpp (1 hunks)
  • src/Editor/src/OsreEdApp.cpp (2 hunks)
  • src/Editor/src/main.cpp (2 hunks)
  • src/Engine/App/AppBase.cpp (1 hunks)
  • src/Engine/App/AppBase.h (2 hunks)
Additional comments not posted (12)
src/Editor/src/main.cpp (3)

37-37: LGTM!

Commenting out the inclusion of PlatformOperations.h aligns with the removal of the code segment responsible for opening a file dialog to select an asset for import. This change suggests a shift away from using platform-specific operations for file dialogs, as mentioned in the AI-generated summary.


55-55: LGTM!

The modifications to the initWindow function call, including the additional parameters for window mode and type, suggest a more flexible window configuration. The changes involve replacing boolean parameters with enumerated types, enhancing clarity and type safety, as mentioned in the AI-generated summary and the alterations to the declarations of exported or public entities.


63-65: LGTM!

The streamlined main loop, focusing on event handling, updating, and requesting the next frame, enhances the clarity and efficiency of the main application loop. The removal of the code segment responsible for opening a file dialog to select an asset for import indicates a shift towards a more event-driven architecture, where the application continuously processes events and updates without the previous asset loading mechanism, as mentioned in the AI-generated summary.

samples/03_Instancing/Instancing.cpp (1)

119-119: LGTM!

The change from boolean parameters to enumerated types (WindowMode::Windowed and WindowType::Root) in the initWindow function call is a good practice. It enhances code clarity, readability, and maintainability by using descriptive enumerations instead of generic boolean flags. This change makes the function call more self-explanatory and less error-prone, while preserving the overall functionality of the application.

samples/00_HelloWorld/HelloWorld.cpp (1)

108-110: LGTM!

The added conditional check enhances the robustness of the key handling logic by preventing unnecessary updates when an unknown key is detected. The code segment is implemented correctly and follows the existing code style.

src/Editor/src/OsreEdApp.cpp (1)

164-166: LGTM!

The adjustment to the key handling logic is a good improvement. It ensures that the keyboard transformation controller is only updated when a valid key is detected, preventing unnecessary updates and potentially improving performance.

samples/01_ModelLoading/ModelLoading.cpp (1)

188-188: LGTM!

The change from boolean parameters to enumerated types (WindowMode::Windowed and WindowType::Root) for specifying the window mode and type is a good refactoring that enhances code clarity, type safety, and maintainability. Using enumerated types provides a clear and explicit way to define the window configuration, eliminating potential ambiguity and reducing the chances of passing incorrect boolean values. This change aligns with best practices for self-documenting code.

samples/04_terrain/TerrainRendering.cpp (1)

208-208: LGTM!

The change from boolean flags to enumerated types WindowMode::Windowed and WindowType::Root for specifying the window properties in the initWindow function call is a good refactoring. It enhances code clarity, readability, and maintainability by providing a more explicit and self-documenting way to set the window mode and type.

The use of enumerated types also improves type safety by restricting the possible values to a predefined set, reducing the chances of passing invalid or unintended values.

Overall, this change aligns with good coding practices and enhances the quality of the codebase without altering the functionality of the application.

src/Engine/App/AppBase.cpp (1)

85-94: LGTM! The changes improve code clarity and extensibility.

Replacing the boolean parameters fullscreen and childWindow with enums WindowMode and WindowType offers several benefits:

  1. It enhances code readability by using more descriptive names for the window behavior, making the function's purpose clearer at a glance.
  2. It improves type safety and extensibility by restricting the possible values to a predefined set of options, reducing the chances of passing invalid arguments and allowing for easier future modifications if additional window modes or types need to be introduced.

The updated logic correctly reflects the new parameter types by comparing the mode against WindowMode::Fullscreen and the type against WindowType::Child, maintaining the original behavior while improving the semantic clarity of the code.

Great job on this refactoring!

src/Engine/App/AppBase.h (3)

106-111: LGTM!

The new WindowMode enum class is a great addition. It provides a type-safe way to represent different window modes, enhancing code clarity and reducing potential errors. The enum values are well-chosen and follow the naming convention. The Invalid and Count values are useful for error handling and bounds checking.


113-118: LGTM!

The new WindowType enum class is a great addition. It provides a type-safe way to represent different window types, enhancing code clarity and reducing potential errors. The enum values are well-chosen and follow the naming convention. The Invalid and Count values are useful for error handling and bounds checking.


160-160: Verify the impact of the changes.

The changes to the initWindow method signature, replacing the boolean parameters with the new WindowMode and WindowType enums, are a good improvement. They enhance the clarity and extensibility of the window initialization process by using enumerated types instead of boolean flags, which improves code readability and reduces potential errors related to parameter interpretation.

However, please ensure that the method implementation and all its usages are updated to handle the new parameters correctly. You can use the following script to verify the impact:

Verification successful

Verification successful: Changes to initWindow method signature are correctly implemented.

The initWindow method declaration has been updated to use WindowMode and WindowType enums, and all usages in the codebase have been updated to match the new signature. No old usages with boolean parameters were found. The changes enhance code readability and maintainability.

  • Method declaration updated in src/Engine/App/AppBase.h.
  • Usage updated in src/Editor/src/main.cpp.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the changes to the `initWindow` method signature.

# Test 1: Search for the method declaration. Expect: Only the new signature.
rg --type cpp -A 5 $'bool\s+initWindow\s*\(\s*ui32\s+x\s*,\s*ui32\s+y\s*,\s*ui32\s+width\s*,\s*ui32\s+height\s*,\s*const\s+String\s*&\s*title\s*,\s*WindowMode\s+mode\s*,\s*WindowType\s+type\s*,\s*RenderBackendType\s+renderer\s*\)'

# Test 2: Search for the method usages. Expect: All usages updated to match the new signature.
rg --type cpp -A 5 $'initWindow\s*\(\s*\w+\s*,\s*\w+\s*,\s*\w+\s*,\s*\w+\s*,\s*[\w"]+\s*,\s*[\w:]+\s*,\s*[\w:]+\s*,\s*[\w:]+\s*\)'

Length of output: 696


Script:

#!/bin/bash
# Description: Broaden the search for the `initWindow` method declaration and check for old usages.

# Search for any `initWindow` method declaration to verify if it has been updated.
rg --type cpp -A 5 'bool\s+initWindow\s*\('

# Search for any old usages of the `initWindow` method signature with boolean parameters.
rg --type cpp -A 5 $'initWindow\s*\(\s*\w+\s*,\s*\w+\s*,\s*\w+\s*,\s*\w+\s*,\s*[\w"]+\s*,\s*(true|false)\s*,\s*(true|false)\s*,\s*[\w:]+\s*\)'

Length of output: 673

@kimkulling kimkulling merged commit d539d80 into master Sep 13, 2024
3 checks passed
@kimkulling kimkulling deleted the kimkulling/fix_editor_loading branch September 13, 2024 06:34
This was referenced Sep 18, 2024
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

Successfully merging this pull request may close these issues.

2 participants